About {} and its limits
Alexandre Bergel
bergel at iam.unibe.ch
Sat Feb 12 19:08:46 UTC 2005
> Syntactic suger. Like -> instead of Association>>key:value:
Yep, I know that. But I see the Array>>brace* methods as redundant. For instance,
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Array>>braceWith: a with: b
"This method is used in compilation of brace constructs.
It MUST NOT be deleted or altered."
| array |
array _ self new: 2.
array at: 1 put: a.
array at: 2 put: b.
^ array
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
and
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ArrayedCollection>>with: firstObject with: secondObject
"Answer a new instance of me, containing firstObject and secondObject."
| newCollection |
newCollection _ self new: 2.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
^newCollection
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
the brace* methods are copies of methods provided by ArrayedCollection
Alexandre
>
> Nice and terse. Keeps the code pretty.
>
> Also, the {} can support any number of items as the implementation uses a
> stream. I think Array>>with:with:with:... maxes out after a handfil of
> values.
>
> Brent
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel http://www.iam.unibe.ch/~bergel
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
More information about the Squeak-dev
mailing list
|