Block evaluation

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

Block evaluation

Ulrich Hermann
Hi,

I try to evalute the following block, but it doesn't work. I allways  
got a error message.

| x y z |
x:= [ y:=1. z:=2. x+y. ] .  x value.  [] in UndefinedObject>>DoIt  
{[y := 1.  z := 2]}


Regards
Ulli


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

Re: Block evaluation

Ulrich Hermann

Soory , of course it must be : x:= [ y:=1. z:=2. z+y. ] .  x value.
and this works.

But why can't I do this:
   x:= [ y:=1. z:=2. z+y. ] .
and evaluate it later?


Regards
Ulli


Am 18.12.2006 um 01:04 schrieb Ulrich Hermann:

> Hi,
>
> I try to evalute the following block, but it doesn't work. I  
> allways got a error message.
>
> | x y z |
> x:= [ y:=1. z:=2. x+y. ] .  x value.  [] in UndefinedObject>>DoIt  
> {[y := 1.  z := 2]}
>
>
> Regards
> Ulli
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

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

Re: Block evaluation

Giovanni Corriga
In reply to this post by Ulrich Hermann
Il giorno lun, 18/12/2006 alle 01.04 +0100, Ulrich Hermann ha scritto:
> Hi,
>
> I try to evalute the following block, but it doesn't work. I allways  
> got a error message.
>
> | x y z |
> x:= [ y:=1. z:=2. x+y. ] .  x value.  [] in UndefinedObject>>DoIt  
> {[y := 1.  z := 2]}

That is not an error message, it's just what get's print out when you do
a PrintIt of the the first expression. Try doing a PrintIt of both
expressions, and you should get the right result.

        Giovanni

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

Re: Block evaluation

Jerome Peace
In reply to this post by Ulrich Hermann
Block evaluation

Hi Ulli,

I tried your code out in a workspace.
Here is what I discovered.

The original:

| x y z |
x:= [ y:=1. z:=2. x+y. ] .  x value.  
{[y := 1.  x := 2]  } .


Ah this is a cool bug.

As you probably know,
"[ anything ]" is an object called a block context
x:= [ anything ] . x value .
will print the value of "anything" in this case "nil"
since we have not defined it.

There is a typo (I believe) in your second line. I am
guessing you wanted to write.
x:= [ y:=1. z:=2. z+y. ] . x value.
which gives the result 3.
as it stands you are trying to add a number to a block
context which gives a DNU.

The last line is also interesting
Try
{ y:= 1 . z := 2 }
ans: " #(1 2)"

or
{[y := 1.  x := 2] value }" ans: #(2)"

or
{[y := 1.  x := 2]  } first value " 2"


The square brackets are causing the evaluation of "y
:= 1.  x := 2"
to be delayed until later. The thing that prints out
what is going on it being more cryptic than it needs
to be by not printing the contents of the block
context which you would have more immediately
recognized.

hth.

Yours in service, -- Jerome Peace









__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners