Undeclared variable issue

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

Undeclared variable issue

Edward A. Waugh
The following code doesn't execute in my Squeak workspace
 
| n |
n <- 5 factorial.
n printString
 
because it insists that n is undeclared despite that I have declare the it in the first line of the 3 line code fragment.  (I highlight all 3 lines and use the "do it" to execute it.)
 
What is going here - this is valid Smalltalk syntax?
 
Thanks,
Edward
 

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Undeclared variable issue

Roel Wuyts
Try:

| n |
n := 5 factorial.
n printString


Some more explanation: -> is a binary message sent to a receiver  
object to create an association (an instance of class Association  
that is basically a key/value pair). For example, inspect the result  
of the following expression in a workspace:

3 -> 4

In your original piece of code, when you do n -> 5, variable n is  
indeed undefined, and if you proceed it will create an association  
between the 'nil' object (yes, it is a real object as well) and 5.

If you want, you can look up the implementation of the selector ->,  
for example by using the Selector Browser in your tools flab (the one  
at the right), and you will then find that there is a method -> on  
class Object with the following implementation:


-> anObject
        "Answer an Association between self and anObject"

        ^Association basicNew key: self value: anObject


On 05 Sep 2006, at 20:17, Edward A. Waugh wrote:

> The following code doesn't execute in my Squeak workspace
>
> | n |
> n <- 5 factorial.
> n printString
>
> because it insists that n is undeclared despite that I have declare  
> the it in the first line of the 3 line code fragment.  (I highlight  
> all 3 lines and use the "do it" to execute it.)
>
> What is going here - this is valid Smalltalk syntax?
>
> Thanks,
> Edward
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners