Code Blocks

Ken Causey ken at kencausey.com
Tue Aug 31 15:25:16 PDT 2004


On Tue, 2004-08-31 at 17:09, Pupeno wrote:
> 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:
> 

But that's not what my example evaluates to.

generateSampleBlock is not passed to executeExampleBlock in that case. 
It is evaluated and the block is returned.  And that returned block is
passed to executeExampleBlock.  At least I think that's the case.  Let's
test it.  Redefine generateExampleBlock like so:

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

Repeated for clarity:

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

And now let's execute the test a little differently.

Slate 9> addSlot: #testBlock.
(Mixins . Types . VM . prototypes .
	testBlock . globals . traits )
Slate 10> testBlock: generateExampleBlock.
At definition time
[]
Slate 11> executeExampleBlock: testBlock.
3
Nil

I have to admit that I'm not sure how to test my theory above that in
the original example generateExampleBlock is executed and not passed. 
But anyway this example is better I guess.

Your example below is fine as well.

Ken

> 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-----
-------------- 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/9f40eed2/attachment.pgp


More information about the Slate mailing list