Newbie q
Jecel Assumpcao Jr
jecel at merlintec.com
Fri Sep 26 17:50:59 UTC 2003
On Friday 26 September 2003 10:52, Phil Hudson wrote:
> Thanks Göran. I'm convinced.
Awww... you gave up too easily. In the Self dialect of Smalltalk (those
of you thinking of writing me that "Self isn't Smalltalk", please don't
bother) a context is created by cloning the method object. So any
temporary variables should have valid values *before* execution starts.
Something like
myMethod: arg = (
| x <- 10. y <- 'Hubba'. z = picture from: 'FCD045F07' |
....
)
The 'z' temporary variable is actually a constant rather than a
variable, which if one thing you can't have when initializing in the
method body instead of the declarations. Another subtle difference
relative to
myOtherMethod: arg (
| x. y. z |
x: 10.
y: 'Hubba'.
z: picture from: 'FCD045F07'.
...
)
is that now the code for these initializations is executed each time the
method is invoked, while in the first example they were executed while
creating the method object. The really makes little diffence for things
like 10 or 'Hubba', but if the picture creation method is slow then the
first version is much more interesting.
Yes, Smalltalk has been around for 31 years now. But it is never to late
to learn new tricks ;-)
-- Jecel
More information about the Squeak-dev
mailing list
|