[Pharo-project] Block semantics ....

Eliot Miranda eliot.miranda at gmail.com
Mon Nov 29 03:42:10 CET 2010

On Sun, Nov 28, 2010 at 1:37 PM, James Ladd <james_ladd at hotmail.com> wrote:

>  Hi All,
> I'm wondering about documentation to describe the block semantics of Pharo
> Smalltalk,
> Specifically around the return context when a block contains a return:  [ ^
> foo ]
> Is a block valid only within the method that defined it and passed / called
> it?
> I think it is, and when called outside of the context there is a
> BlockContext no longer exists error.

Note that BlockContext is no longer used.  | b | b := [thisContext class].
 { b class. b value } answers { BlockClosure. MethodContext }.

The block is valid, but the attempt to return from a method can only be made
once, whether made form an embedded block or the mehtod itself.  So the
first attempt to retur wins.  However, a block =containing a return can
still be evaluated.  An error will occur only if the retrn is actually

So e.g.
        | b |
        ^b := [:n| n < 0 ifTrue: [^self error: 'Nooooooo!'].  n < 2 ifTrue:
[1] ifFalse: [(b value: n - 1) + (b value: n - 2)]]

    (0 to: 10) collect: self fibBlock

works fine but

     self fibBlock value: -1

will produce a cannot return error.

> However, I'm looking for documentation or confirmation to ensure my testing
> was correct.
> Rgs, James.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20101128/ce5331d0/attachment.htm>

More information about the Pharo-project mailing list