Not quite literally, let me check the Dictionary...

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

Not quite literally, let me check the Dictionary...

Casey Ransberger-2
I was wondering what folks might think of...

Dictionary on: { #foo->23. #bar->42. #baz->123 }

Please find attached change set. Two methods; one that matches the selector pattern for instance creation methods on Dictionary, one that wraps it with a nice, concise, #on:.

It's not quite a dictionary literal, but it works nicely enough, and requires no new syntax.

--
Casey Ransberger



DictionaryNotQuiteLiteral.1.cs (984 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Hans-Martin Mosner
Am 02.05.2010 07:00, schrieb Casey Ransberger:
> I was wondering what folks might think of...
>
> Dictionary on: { #foo->23. #bar->42. #baz->123 }
Are you aware that
{ #foo->23. #bar->42. #baz->123 } as: Dictionary
already exists in the system?
So I think this would be unnecessary duplication of functionality.

Cheers,
Hans-Martin

Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Igor Stasenko
On 2 May 2010 09:59, Hans-Martin Mosner <[hidden email]> wrote:
> Am 02.05.2010 07:00, schrieb Casey Ransberger:
>> I was wondering what folks might think of...
>>
>> Dictionary on: { #foo->23. #bar->42. #baz->123 }
> Are you aware that
> { #foo->23. #bar->42. #baz->123 } as: Dictionary
> already exists in the system?

At least i'm not. Thanks for pointing out.

> So I think this would be unnecessary duplication of functionality.
>

Sometimes i really miss the Dictionary literals :(

> Cheers,
> Hans-Martin
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Casey Ransberger-2
In reply to this post by Hans-Martin Mosner
Aha, thank you. That's why I posted :)

On Sat, May 1, 2010 at 11:59 PM, Hans-Martin Mosner <[hidden email]> wrote:
Am 02.05.2010 07:00, schrieb Casey Ransberger:
> I was wondering what folks might think of...
>
> Dictionary on: { #foo->23. #bar->42. #baz->123 }
Are you aware that
{ #foo->23. #bar->42. #baz->123 } as: Dictionary
already exists in the system?
So I think this would be unnecessary duplication of functionality.

Cheers,
Hans-Martin




--
Casey Ransberger


Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Levente Uzonyi-2
On Sun, 2 May 2010, Casey Ransberger wrote:

> Aha, thank you. That's why I posted :)

It's actually Dictionary class >> #newFrom: which can create a dictionary
from an array of associations. There are some examples at the end of the
method using this feature, but they are flawed, because NewDictionary is
not a class).
This feature works because every collection understands #associationsDo:
(yeah, it's not so nice) and #size, so not just arrays, but any collection
of associations can be the argument of #newFrom:.


Levente

>
> On Sat, May 1, 2010 at 11:59 PM, Hans-Martin Mosner <[hidden email]> wrote:
>
>> Am 02.05.2010 07:00, schrieb Casey Ransberger:
>>> I was wondering what folks might think of...
>>>
>>> Dictionary on: { #foo->23. #bar->42. #baz->123 }
>> Are you aware that
>> { #foo->23. #bar->42. #baz->123 } as: Dictionary
>> already exists in the system?
>> So I think this would be unnecessary duplication of functionality.
>>
>> Cheers,
>> Hans-Martin
>>
>>
>
>
> --
> Casey Ransberger
>

Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Igor Stasenko
On 2 May 2010 11:55, Levente Uzonyi <[hidden email]> wrote:

> On Sun, 2 May 2010, Casey Ransberger wrote:
>
>> Aha, thank you. That's why I posted :)
>
> It's actually Dictionary class >> #newFrom: which can create a dictionary
> from an array of associations. There are some examples at the end of the
> method using this feature, but they are flawed, because NewDictionary is not
> a class).
> This feature works because every collection understands #associationsDo:
> (yeah, it's not so nice) and #size, so not just arrays, but any collection
> of associations can be the argument of #newFrom:.
>

Ohh. There is a very bad inconsistency with Collection protocol in Dictionary,
which makes me sad:

| dict array |

dict := Dictionary new.

dict add:  'a' -> 'b'.

self assert: (dict at: 'a') = 'b'.

array := Array with: 'c'->'d'.

dict addAll: array.

self assert: (dict at: 'c') = 'd'


Collection>>addAll: comment reads:

addAll: aCollection
        "Include all the elements of aCollection as the receiver's elements. Answer
        aCollection. Actually, any object responding to #do: can be used as argument."

Collection>>add: comment reads:

add: newObject
        "Include newObject as one of the receiver's elements. Answer newObject.
        ArrayedCollections cannot respond to this message."


So, is everyone ok with such dichotomy?
I am certainly not.

If Dictionary takes an association in its #add:
then it should also take a collection of associations in #addAll: ?

And if not, then Dictionary>>add:  should not be supported, but
provide alternative method -  Dictionary>>addAssociation: .

>
> Levente
>

--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: Not quite literally, let me check the Dictionary...

Igor Stasenko
Same thing:


a := Dictionary with: 1->2

b := Dictionary withAll:  { 1->2 }

self assert: a = b

On 2 May 2010 12:21, Igor Stasenko <[hidden email]> wrote:

> On 2 May 2010 11:55, Levente Uzonyi <[hidden email]> wrote:
>> On Sun, 2 May 2010, Casey Ransberger wrote:
>>
>>> Aha, thank you. That's why I posted :)
>>
>> It's actually Dictionary class >> #newFrom: which can create a dictionary
>> from an array of associations. There are some examples at the end of the
>> method using this feature, but they are flawed, because NewDictionary is not
>> a class).
>> This feature works because every collection understands #associationsDo:
>> (yeah, it's not so nice) and #size, so not just arrays, but any collection
>> of associations can be the argument of #newFrom:.
>>
>
> Ohh. There is a very bad inconsistency with Collection protocol in Dictionary,
> which makes me sad:
>
> | dict array |
>
> dict := Dictionary new.
>
> dict add:  'a' -> 'b'.
>
> self assert: (dict at: 'a') = 'b'.
>
> array := Array with: 'c'->'d'.
>
> dict addAll: array.
>
> self assert: (dict at: 'c') = 'd'
>
>
> Collection>>addAll: comment reads:
>
> addAll: aCollection
>        "Include all the elements of aCollection as the receiver's elements. Answer
>        aCollection. Actually, any object responding to #do: can be used as argument."
>
> Collection>>add: comment reads:
>
> add: newObject
>        "Include newObject as one of the receiver's elements. Answer newObject.
>        ArrayedCollections cannot respond to this message."
>
>
> So, is everyone ok with such dichotomy?
> I am certainly not.
>
> If Dictionary takes an association in its #add:
> then it should also take a collection of associations in #addAll: ?
>
> And if not, then Dictionary>>add:  should not be supported, but
> provide alternative method -  Dictionary>>addAssociation: .
>
>>
>> Levente
>>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>



--
Best regards,
Igor Stasenko AKA sig.