Steve, sorry but in the example [ add = method(n, block(x, x + n)) ] i don't understand ...
Where does x live?
If I invoke a = add(10) then it signified to execute a method with 1 argument (n) whose functionality is to process x+n, but where is x?
Thanks...
Pablo
From: Steve Dekorte steve@dekorte.com Reply-To: self-interest@yahoogroups.com To: self-interest@yahoogroups.com Subject: Re: [self-interest] Re: blocks Date: Thu, 20 Nov 2003 13:30:16 -0800
On Nov 20, 2003, at 12:35 PM, Jecel Assumpcao Jr wrote:
It certainly does work, but I wouldn't call it simple. Since Self doesn't allow non-lifo blocks, I'll rewrite your example in Smalltalk instead:
MyObject>>add: n ^ [:x | x + n]
a := myObject add: 10. b := myObject add: 20.
Transcript show: (a value: 10). Transcript show: (b value: 10).
I don't understand why this is simpler. Could you explain? It's not important, I'm just confused and would prefer not to be. :-)
Here's a simplified Io version:
add = method(n, block(x, x + n)) a = add(10) b = add(20) a(10) print b(10) print
-- Steve
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
_________________________________________________________________ Charla con tus amigos en lĂnea mediante MSN Messenger: http://messenger.latam.msn.com/
On Nov 21, 2003, at 4:41 AM, Pablo de Marcos wrote:
Steve, sorry but in the example [ add = method(n, block(x, x + n)) ] i don't understand ...
Where does x live?
It is an argument off the block.
If I invoke a = add(10) then it signified to execute a method with 1 argument (n) whose functionality is to process x+n, but where is x?
No, it's functionality it to return the block "block(x, x + n)". This is then assigned to the value a. When we call:
a(10)
it activates the block with the argument 10 which is what x is set to. the block finds n in it's enclosing context which is the locals that where created when the add method was called.
-- Steve
self-interest@lists.selflanguage.org