Code Blocks

Ken Causey ken at kencausey.com
Tue Aug 31 14:28:34 PDT 2004


Pupeno's is not a terrible example but it's not great.  So here's my
attempt.

_ at lobby generateExampleBlock
[ | testValue |
  testValue: 3.
  ^ [Console ; (testValue as: String) ; '\n']
].

_ at lobby executeExampleBlock: aBlock
[  | testValue |
   testValue: 5.
   aBlock do.
].

executeExampleBlock: generateExampleBlock.

Slate 4> executeExampleBlock: generateExampleBlock.
3
Nil

The point to take here is that even though in the context where the
block was executed testValue redefined to be 5 the value output was 3
which is what the value was in the 'lexical' context where the block was
defined.

Ken

P.S. My experience with Slate is still somewhat limited so don't take
the code above as anything other than example of the concept of lexical
closure and maybe not even a great one of that.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : /archives/slate/attachments/20040831/d3640166/attachment.pgp


More information about the Slate mailing list