how do i compile '[ :foo | foo bar]' on the fly so that i can store it in an instance variable and send value: to it sometime later on?
also, what if i reference self in the block, like '[ :foo | foo bar: self]'. what do i need to do to make sure that self evaluates to the object that is holding the block?
thanks, dave
-- j. david farber oo architect+mentor numenor labs incorporated in sunny boulder colorado dfarber@numenor.com www.numenor.com
At 04:36 PM 4/28/98 -0300, David Farber wrote:
how do i compile '[ :foo | foo bar]' on the fly so that i can store it in an instance variable and send value: to it sometime later on?
also, what if i reference self in the block, like '[ :foo | foo bar: self]'. what do i need to do to make sure that self evaluates to the object that is holding the block?
You can look at the Compiler>>evaluate:in:to:notifying:ifFail: method. Here's an example:
Integer>>foo | test block | test := 5. block := Compiler new evaluate: '[:a | a + test + self]' in: thisContext to: self notifying: nil ifFail: [nil]. ^block value: 10
4 foo ==> 19 (a=10, test=5, self=4)
John Brant
squeak-dev@lists.squeakfoundation.org