[squeak-dev] Re: BlockClosure vs BlockContext

Randal L. Schwartz merlyn at stonehenge.com
Wed Aug 4 15:02:34 UTC 2010


>>>>> "Randal" == Randal L Schwartz <merlyn at stonehenge.com> writes:

>>>>> "John" == John Chludzinski <john.chludzinski at gmail.com> writes:
John> How about:
John> test1

John> | block w z |
John> w := 3. z := 12.
John> block := { [ :a :b | Transcript show: a asString , '   ' , b asString; cr ]
John> . w . z }.
John> w := 0. z := 1.
John> (block at: 1) value: (block at: 2) value: (block at: 3)

Randal> Yeah, now that closures work, you could effectively curry the values:

Randal>     | block w z |
Randal>     w := 3.
Randal>     z := 12.
Randal>     block :=
Randal>       [:captureW :captureZ |
Randal>         [Transcript show: captureW asString , ' ' , captureZ asString; cr]]
Randal>           value: w value: z.

Randal>     w := 0.
Randal>     z := 1.

Randal>     block value.  "should still show 3, 12"

Randal> There might even be a method for that... or it might have just been
Randal> Seaside specific.

Ahh yes, #cull:cull:

    | block w z |
    w := 3.
    z := 12.
    block := [:newW :newZ | ... ] cull: w cull: z.
    w := 0.
    z := 1.
    block value.

Should do it.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion



More information about the Squeak-dev mailing list