Brace Bracket assignment for two arguments vs >>become: (Was: Squeak programming question)

Mark Wai mwai at ibm.net
Tue Mar 23 04:15:05 UTC 1999


At 12:31 PM 3/22/99 -0800, Dan Ingalls wrote:

>I pretty much subscribe to the solutions proffered so far (returning an 
>array and using a block).  However I offer the following for your 
>entertainment (fasten seat belts)...

I did fastened my seat belts, but I still crashed (see below).

>snip<
>
>In fact you can even do
>
>	{a. b} := {b. a}
>
>to exchange two values without a third temporary variable.

This is wonderful.  It is very fast.  Extremely fast.  Much faster than I
thought.

The above example looks like an alternative way to do two way become.  Out
of curiosity,  I did a little experience to see the differences (under 2.3
image on OS/2):

| a b |

a := OrderedCollection new.
b := Array new: 100000.
1 to: 100000 do:[:i | a add: i].
1 to: 100000 do:[:i | b at: i put: i].

First test:		Time millisecondsToRun:[ a become: b ] ==> 23
Second test:		Time millisecondsToRun:[ {a.b} := {b.a} ] ==> 0 

What the heck is going on with this curly brackets?  How can this be that
much faster?  Did I use a bad test bed?  If this is case, why can't we
implement something like (forget the crash, I am talking about idea here):

>>become: anotherObject

	{self.anotherObject} := {anotherObject.self}



--
Mark Wai
Wator InnoVision





More information about the Squeak-dev mailing list