[Squeak] Newbie permutations

goran.hultgren at bluefish.se goran.hultgren at bluefish.se
Tue Apr 9 08:45:03 UTC 2002


"Duane Maxwell" <dmaxwell at san.rr.com> wrote:
> From: "Michael Grant" <mwgrant2001 at yahoo.com>
[SNIP]
> > Can someone enlighten me? It must be simple, but...
> 
> One way:
> 
> a := OrderedCollection new.
> #(1 3 5) permutationsDo: [:each | a addLast: each copy ].
> a

The copy is not really needed. But you should then be aware of the fact
that
if the loop does something more with "each" then it will be the same
Arrays that are referenced from the OrderedCollection.

A "trick" to understand Smalltalk variables is that an assignment:

a := expression

...means exactly "let the variable a refer to the object that is the
result of the expression".

So:

a := b

(where "b" is a trivial expression) means "let the variable a refer to
the same object that b refers to". So all assignements in Smalltalk are
"by reference" and not by value (well, SmallIntegers are a tad special
since they are not really objects - the value is encoded inside the oop
(=pointer).)

And in the same spirit we say that a message send:

a printString

...means exactly "send the message #printString to the object that a
refers to".

regards, Göran
 
> > P.S. If there is a more appropriate list for newbie
> > please let me know. 
> 
> This is the correct list.
> 
> -- Duane

Yes, this is definitely the correct list. Many discussions here are
"advanced" for a newbie but on the other hand there is a lot to learn by
them! So don't be afraid to post.

regards, Göran



More information about the Squeak-dev mailing list