Newbie question
Bert Freudenberg
bert at freudenbergs.de
Mon Jul 23 20:51:33 UTC 2007
On Jul 23, 2007, at 21:58 , Blake wrote:
> On Mon, 23 Jul 2007 12:27:21 -0700, subbukk <subbukk at gmail.com> wrote:
>
>> On Monday 23 July 2007 11:39 pm, Bert Freudenberg wrote:
>>
>>> Now, at one point the compiler even supported this:
>>>
>>> {a. b} := {1. 2}
>>>
>>> which I found cool but was considered evil, even by those who
>>> tolerate the braces ...
>
> What would this do? It looks like you're assigning a literal to
> another literal?
No, it is equivalent to
a := 1.
b := 2.
The left-hand side must only be variables separated by dots.
This allows to swap two variables without a temp:
{a. b} := {b. a}
which admittedly you rarely need to do except in some special
algorithms.
Or, you could use it for returning multiple objects from a message
and store immediately in some temps. Which admittedly is bad style,
you should use an object for that (or pass a block in).
So there are some who think this is a useful construct, also many
"scripting languages" have it. But it goes against the "spirit" of
Smalltalk. Assignment itself is not "pure" but this kind of multi-
assignment was considered to do more harm than good. Whereas the
brace construct for array construction was too useful to pass.
- Bert -
More information about the Squeak-dev
mailing list
|