Strange behaviour of dictionary

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange behaviour of dictionary

jannik laval
Hi all,

There is something that I do not understand in Dictionary.
I am not sure this is what we want.

The following code:
===
Dictionary new addAll:
{#a -> #b.
#c -> #d }; yourself
===
returns "a Dictionary(1->#a->#b 2->#c->#d )"

where I would like to have  "a Dictionary(#a->#b #c->#d )".

Ok, I do
===
{#a -> #b.
#c -> #d } asDictionary
===
and it works.

Jannik

Reply | Threaded
Open this post in threaded view
|

Re: Strange behaviour of dictionary

Sven Van Caekenberghe-2

On 11 Mar 2013, at 22:40, "jannik.laval" <[hidden email]> wrote:

> Hi all,
>
> There is something that I do not understand in Dictionary.
> I am not sure this is what we want.
>
> The following code:
> ===
> Dictionary new addAll:
> {#a -> #b.
> #c -> #d }; yourself
> ===
> returns "a Dictionary(1->#a->#b 2->#c->#d )"
>
> where I would like to have  "a Dictionary(#a->#b #c->#d )".
>
> Ok, I do
> ===
> {#a -> #b.
> #c -> #d } asDictionary
> ===
> and it works.
>
> Jannik

Cool, I never saw that, the #asDictionary, very handy. I often use #newFromPairs:

You can also write:

Dictionary newFrom: { #foo->1. #bar->2 }.

For some reason, Dictionary>>#add: takes an association as argument, while Dictionary>>#addAll: takes a keyed collection.

Sven


--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill