[self-interest] Re: blocks

Pablo de Marcos deMarcosP at Hotmail.com
Fri Nov 21 12:41:14 UTC 2003


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 at dekorte.com>
Reply-To: self-interest at yahoogroups.com
To: self-interest at 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/




More information about the Self-interest mailing list