[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail |
Date: |
Fri, 23 Mar 2007 15:26:38 +0100 |
User-agent: |
Thunderbird 1.5.0.10 (Macintosh/20070221) |
> Taken literally, the standard says "nothing but Dictionary". But my
> point is, if a Dictionary is a Collection of Associations, any such
> Collection can be used.
The point is that it is not. The standard has no mention of
Associations at all, and that's a really good thing.
While the standard does not give any relationship between
Dictionaries and any other collection, there is only one that is
coherent with the rest of the standard: keyed collections in
Smalltalk are SequenceableCollections and Dictionaries (the keys
being integers in the case of seq. collections). Keyed collections
would be those that implement #keysAndValuesDo: (and if you search
for "keyed" in the standard, you'll see what I mean).
> This isn't a violation of standard. It's
> interpretation. That's what "abstract" in "<abstractDictionary>" means.
> "If it walks like a duck and quacks like a duck, ..."
... but then, since, #('a' 'b' 'c') implements #keysAndValuesDo:,
"Dictionary withAll: #('a' 'b' 'c')" will give a
Dictionary with 1->'a', 2->'b', and 3->'c'. This also can be
seen as "If it walks like a duck and quacks like a duck".
But the point is that the standard guys were *right* in dropping
Associations and "#add:" from it. "#add:" makes no sense with
external keys, and it percolates Associations (which are an
implementation detail) to the definition of Dictionary.
One possibility could be to extend the {...} syntax to something
like "OrderedCollection {...}", "Dictionary {...}", and have it send
messages like "#braceWithAll:". Then you would have:
Array >> braceWithAll: x
^self
Collection >> braceWithAll: x
^self withAll: x
Dictionary >> braceWithAll: x
| dict |
dict := self new: x size * 2.
"in the loop we want 'self add: x' maybe?"
x do: [ :each | dict at: x key put: x value ].
^dict
The compiler might know of a few classes and optimize them;
or maybe not.
Paolo
- [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, parasti, 2007/03/20
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Paolo Bonzini, 2007/03/20
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Stephen Compall, 2007/03/22
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Jānis Rūcis, 2007/03/22
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Stephen Compall, 2007/03/22
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Paolo Bonzini, 2007/03/23
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Jānis Rūcis, 2007/03/23
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Paolo Bonzini, 2007/03/23
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail, Jānis Rūcis, 2007/03/23
- Re: [Help-smalltalk] CharacterArray class>>#lineDelimiter and Dictionary>>#addAll: both fail,
Paolo Bonzini <=
- Re: [Help-smalltalk] Dictionary>>#addAll: fails, Stephen Compall, 2007/03/23
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Paolo Bonzini, 2007/03/26
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Stephen Compall, 2007/03/29
- Re: [Help-smalltalk] Re: Dictionary>>#addAll: fails, Paolo Bonzini, 2007/03/30
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Stephen Compall, 2007/03/29
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Jānis Rūcis, 2007/03/29
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Stephen Compall, 2007/03/29
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Jānis Rūcis, 2007/03/30
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Stephen Compall, 2007/03/30
- [Help-smalltalk] Re: Dictionary>>#addAll: fails, Jānis Rūcis, 2007/03/31