[Squeakland] When to define a local variable

Laurence Rozier laurence.rozier at gmail.com
Sat Mar 31 17:39:35 PST 2007


On 3/31/07, Young-Jin Lee <youngjin.michael at gmail.com> wrote:
>
> Hi,
>
> I am a newbie trying to learn Squeak.
> The squeak book and tutorials says that I need to define a local
> variable using a pipe like below:
>
> | someMuppet |
> someMuppet := Muppet new.
> someMuppet name: 'Elmo'.
> someMuppet greet.
>
> But when I tried the same code without defining a local variable shown
> below, I got the expected results, which makes me wonder when I should
> define a local variable.
>
> anotherMuppet := Muppet new.
> anotherMuppet name: 'Gookie Monster'.
> anotherMuppet greet.
>
> My guess is that I need not define a local variable if my code is
> being executed within a Workspace because all variables such as
> anotherMuppet will have "Workspace" scope.


On the surface this is correct, but the language has no explicit notion of
"Workspace" scope. If you take a look at the comment in the Class Workspace
you can get a sense of how Workspaces end up with this and other
interesting/useful behavior as a result of having the ide written in the
language.  Smalltalk/Squeak is more than the grammar, it is an environment -
the whole is greater than the sum of the parts. Often we do type source code
into text editors as with other languages but eToys, Connectors, Croquet and
other tools offer alternatives. Depending on what language background you're
coming from this may be a subtle but very liberating observation. You may
not need to dig into this but if it seems interesting to you, as you use
different code editing tools in the environment, try your code above or
evaluate the word self.

Enjoy!

Laurence

Can anyone please explain in more detail about variable scopes?

Thanks in advance.
>
> Young-Jin Lee
> _______________________________________________
> Squeakland mailing list
> Squeakland at squeakland.org
> http://squeakland.org/mailman/listinfo/squeakland
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://squeakland.org/pipermail/squeakland/attachments/20070331/c83dbfb8/attachment.htm


More information about the Squeakland mailing list