Code Blocks
Pupeno
pupeno at pupeno.com
Tue Aug 31 15:09:16 PDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday August 31 2004 18:28, Ken Causey wrote:
> 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.
I don't quite agree with this example, if we replace one block in the other we
have:
_ at lobby executeExampleBlock: aBlock
[ | testValue |
testValue: 5.
[ | testValue |
testValue: 3.
^ [Console ; (testValue as: String) ; '\n']
]. do.
].
which obviusly leads to 3 being printed, BUT, that example gives me the clue,
the example should be:
lobby addSlot: #testValue valued: 3.
_ at lobby generateExampleBlock [Console ; (testValue as: String) ; '\n'].
"Create another object called anotherObject, I leave it to someone else, since
I'm not completly sure which object I should clone".
anotherObject addSlot: #testValue: 45.
_ at anotherObject executeExampleBlock: aBlock [ aBlock do. ].
"and running:"
anotherObject executeExampleBlock: lobby generateExampleBlock.
Should print 3, instead of 45.
Right ?
- --
Pupeno: pupeno at pupeno.com - http://www.pupeno.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBNPcOfW48a9PWGkURAg5hAJ4hiN1eFyZ2v/PXWnl0m+HpGnl2jwCfbNv8
/53x8FXGDN7KEDfikUHsmDs=
=U+ue
-----END PGP SIGNATURE-----
More information about the Slate
mailing list