Problem with dict:new()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with dict:new()

Nico Weling
Hi all,

after upgrading to Erlang R8B I've got a lot of badmatch errors due to the 'new' dict module.

How is it possible to use the new release without changing my own programms?


Eshell V4.9.1  (abort with ^G)
1>  D0 = dict:new().
[]


Eshell V5.1  (abort with ^G)
1> D0 = dict:new().
{dict,0,
      16,
      16,
      8,
      80,
      48,
      {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
      {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}


Thanks in advance,

regards Nico.


Reply | Threaded
Open this post in threaded view
|

Problem with dict:new()

Samuel Elliott
On 19/11, Nico Weling wrote:

| after upgrading to Erlang R8B I've got a lot of badmatch errors due to the
| 'new' dict module.

This is your fault :) You should not have assumed anything about the structure
of a dict object.

| How is it possible to use the new release without changing my own programms?

You can't. However, you can rewrite some parts of your code (this should not
represent many lines) to use only functions from the dict module when
manipulating dictionaries. This way, your new code will work fine with both
the old and the new Erlang version.

  Sam



Reply | Threaded
Open this post in threaded view
|

Problem with dict:new()

Björn Gustavsson-3
In reply to this post by Nico Weling
dict was changed already in R7B.

Use the orddict module instead of dict. The orddict module is guaranteed to
be implemented as a list.

/Bjorn

Nico Weling <nico.weling> writes:

> after upgrading to Erlang R8B I've got a lot of badmatch errors due to the 'new' dict module.
>
> How is it possible to use the new release without changing my own programms?
>
>
> Eshell V4.9.1  (abort with ^G)
> 1>  D0 = dict:new().
> []
>
>
> Eshell V5.1  (abort with ^G)
> 1> D0 = dict:new().
> {dict,0,
>       16,
>       16,
>       8,
>       80,
>       48,
>       {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
>       {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
>
>
> Thanks in advance,
>
> regards Nico.
>

--
Bj?rn Gustavsson            Ericsson Utvecklings AB
bjorn      ?T2/UAB/F/P
                            BOX 1505
+46 8 727 56 87    125 25 ?lvsj?


Reply | Threaded
Open this post in threaded view
|

Problem with dict:new()

Robert Virding-4
In reply to this post by Nico Weling
Nico Weling <nico.weling> writes:
>Hi all,
>
>after upgrading to Erlang R8B I've got a lot of badmatch errors due to the 'new' dict module.
>
>How is it possible to use the new release without changing my own programms?

This is just to confirm what other replies have stated.  The internal
representation has changed and dict's are now much more efficient.
Note that the internal representation was was never defined before!

There is a dict:size/1 function which returns the size of the dict,
the number of elements.

There is also another module orddict which has exactly the API as dict
but where the internal representation is defined to be a list of pairs
(tuples) ordered on the first element which is the key.  Here you
could test with [], but it is cleaner to use size/1.  I personally
find that sometimes it is practical to know that the representation is
a list, but with fold/3 I don't need it that often.

Perhaps there should also be a foreach/2?

Robert