Re: [Pharo-users] #collect:as:Dictionary

2015-10-24 Thread Peter Uhnák
What is the practical value of creating a dictionary from non-association
objects? That seems to me like the programmer made a mistake and forgot
something. But maybe you do it regularly, I can only speak for myself.

However consider also this:

 #(a b c) collect: [ :each | each -> each first asciiValue ]  as:
Dictionary. "a Dictionary(1->#a->97 2->#b->98 3->#c->99 )"
(#(a b c) collect: [ :each | each -> each first asciiValue ]) as:
Dictionary. "a Dictionary(#a->97 #b->98 #c->99 )"


Peter

On Sat, Oct 24, 2015 at 12:13 PM, Nicolai Hess 
wrote:

>
>
> 2015-10-23 8:33 GMT+02:00 Marcus Denker :
>
>>
>> > On 23 Oct 2015, at 07:12, Peter Uhnák  wrote:
>> >
>> > Hi,
>> >
>> > is this intentional behavior?
>> >
>> > #(a b c) collect: [ :each | each -> each first asciiValue ] as:
>> Dictionary.
>> > "a Dictionary(1->#a->97 2->#b->98 3->#c->99 )"
>> >
>> > (#(a b c) collect: [ :each | each -> each first asciiValue ])
>> asDictionary.
>> > "a Dictionary(#a->97 #b->98 #c->99 )"
>> >
>> > I would expect that collect:as: for Dictionaries would act in the same
>> way as #asDictionary.
>> >
>> Yes, I would expect the same… asDictionary is fairly recent, though.
>> Before that, any kind
>> of conversion would have been fine.
>>
>> Marcus
>>
>>
>>
> I would not change this.
> The first just collects each entry and builds an association with the
> index,
> and the second expects a list of assocations.
> They have different behaviors if the list does not contains (or does not
> only contains) associations:
>
> {  $a -> 1 . $b -> 2. 'not_an_association' } collect:#yourself
> as:Dictionary. "works - I would not expect an error"
>
> {  $a -> 1 . $b -> 2. 'not_an_association' } asDictionary "throws an error
> - as I would expect it "
>
>
>


Re: [Pharo-users] #collect:as:Dictionary

2015-10-24 Thread Nicolai Hess
2015-10-23 8:33 GMT+02:00 Marcus Denker :

>
> > On 23 Oct 2015, at 07:12, Peter Uhnák  wrote:
> >
> > Hi,
> >
> > is this intentional behavior?
> >
> > #(a b c) collect: [ :each | each -> each first asciiValue ] as:
> Dictionary.
> > "a Dictionary(1->#a->97 2->#b->98 3->#c->99 )"
> >
> > (#(a b c) collect: [ :each | each -> each first asciiValue ])
> asDictionary.
> > "a Dictionary(#a->97 #b->98 #c->99 )"
> >
> > I would expect that collect:as: for Dictionaries would act in the same
> way as #asDictionary.
> >
> Yes, I would expect the same… asDictionary is fairly recent, though.
> Before that, any kind
> of conversion would have been fine.
>
> Marcus
>
>
>
I would not change this.
The first just collects each entry and builds an association with the index,
and the second expects a list of assocations.
They have different behaviors if the list does not contains (or does not
only contains) associations:

{  $a -> 1 . $b -> 2. 'not_an_association' } collect:#yourself
as:Dictionary. "works - I would not expect an error"

{  $a -> 1 . $b -> 2. 'not_an_association' } asDictionary "throws an error
- as I would expect it "


Re: [Pharo-users] #collect:as:Dictionary

2015-10-23 Thread Marcus Denker

> On 23 Oct 2015, at 07:12, Peter Uhnák  wrote:
> 
> Hi,
> 
> is this intentional behavior?
> 
> #(a b c) collect: [ :each | each -> each first asciiValue ] as: Dictionary.
> "a Dictionary(1->#a->97 2->#b->98 3->#c->99 )"
> 
> (#(a b c) collect: [ :each | each -> each first asciiValue ]) asDictionary.
> "a Dictionary(#a->97 #b->98 #c->99 )"
> 
> I would expect that collect:as: for Dictionaries would act in the same way as 
> #asDictionary.
> 
Yes, I would expect the same… asDictionary is fairly recent, though. Before 
that, any kind
of conversion would have been fine.

Marcus