When to define a local variable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

When to define a local variable

Young-Jin Lee-3
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.

Can anyone please explain in more detail about variable scopes?

Thanks in advance.

Young-Jin Lee
_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: When to define a local variable

Scott Wallace
Hi, Young-Jin Lee,

Your guess is exactly correct.  Workspaces assume that any otherwise-
unknown variable is intended to be a "workspace" variable.

Cheers,

   -- Scott


On Mar 31, 2007, at 9:58 AM, Young-Jin Lee 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.
>
> Can anyone please explain in more detail about variable scopes?
>
> Thanks in advance.
>
> Young-Jin Lee
> _______________________________________________
> Squeakland mailing list
> [hidden email]
> http://squeakland.org/mailman/listinfo/squeakland

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: When to define a local variable

Laurence Rozier
In reply to this post by Young-Jin Lee-3

On 3/31/07, Young-Jin Lee <[hidden email]> 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
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland


_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: When to define a local variable

Eric Eisaman
Hello,
 
You mention Croquet as offering alternatives. I have been trying to run Croquet on several different computers but always receive the "Failed to Initiate OpenGL" error however, I recently installed the latest OpenGL on all my computers. Do you know how to deal with this? Also, I get a security error saying my Win32 platform has no good source of entropy. How can I cope with this? If you have any advice I would greatly appreciate it.
 
Eric Eisaman

 
On 4/1/07, Laurence Rozier <[hidden email]> wrote:

On 3/31/07, Young-Jin Lee <[hidden email]> 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
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://squeakland.org/mailman/listinfo/squeakland" target="_blank"> http://squeakland.org/mailman/listinfo/squeakland


_______________________________________________
Squeakland mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://squeakland.org/mailman/listinfo/squeakland" target="_blank">http://squeakland.org/mailman/listinfo/squeakland



_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: When to define a local variable

Laurence Rozier
Hi,
Sorry for the delayed response ... I'm not on a Windows machine at the moment but have applied available fixes to OpenGL problems which you can find on the Croquet list. I've not seen the security error you mention.

Laurence
On 5/7/07, Eric Eisaman <[hidden email]> wrote:
Hello,
 
You mention Croquet as offering alternatives. I have been trying to run Croquet on several different computers but always receive the "Failed to Initiate OpenGL" error however, I recently installed the latest OpenGL on all my computers. Do you know how to deal with this? Also, I get a security error saying my Win32 platform has no good source of entropy. How can I cope with this? If you have any advice I would greatly appreciate it.
 
Eric Eisaman

 
On 4/1/07, Laurence Rozier <[hidden email]> wrote:

On 3/31/07, Young-Jin Lee <[hidden email]> 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
[hidden email]
<a href="http://squeakland.org/mailman/listinfo/squeakland" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://squeakland.org/mailman/listinfo/squeakland


_______________________________________________
Squeakland mailing list
[hidden email]
<a href="http://squeakland.org/mailman/listinfo/squeakland" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://squeakland.org/mailman/listinfo/squeakland




_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland
Reply | Threaded
Open this post in threaded view
|

Re: When to define a local variable

Alan Kay
Hi Folks --

This list is mostly for teachers, parents and children, and is about the Etoys part of Squeak. Please use either the Squeak.org or the opencroquet.org (or one of the other Croquet lists) for these kinds of issues.

Thank you,

Alan

-------------

At 09:11 PM 5/19/2007, Laurence Rozier wrote:
Hi,
Sorry for the delayed response ... I'm not on a Windows machine at the moment but have applied available fixes to OpenGL problems which you can find on the Croquet list. I've not seen the security error you mention.

Laurence
On 5/7/07, Eric Eisaman <[hidden email] > wrote:
Hello,
 
You mention Croquet as offering alternatives. I have been trying to run Croquet on several different computers but always receive the "Failed to Initiate OpenGL" error however, I recently installed the latest OpenGL on all my computers. Do you know how to deal with this? Also, I get a security error saying my Win32 platform has no good source of entropy. How can I cope with this? If you have any advice I would greatly appreciate it.
 
Eric Eisaman

 
On 4/1/07, Laurence Rozier <[hidden email]> wrote:

On 3/31/07, Young-Jin Lee <[hidden email]> 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
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland



_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland



_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland

_______________________________________________
Squeakland mailing list
[hidden email]
http://squeakland.org/mailman/listinfo/squeakland