logo       

Re: Block evaluation: msg#00087

lang.smalltalk.squeak.beginners

Subject: Re: Block evaluation

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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise