[Squeakland] When to define a local variable

Young-Jin Lee youngjin.michael at gmail.com
Sat Mar 31 08:58:47 PST 2007


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.

Can anyone please explain in more detail about variable scopes?

Thanks in advance.

Young-Jin Lee

More information about the Squeakland mailing list