|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
The old block scope debateI've been digging into other languages again, and want to bring up the old
block scope debate. I think Smalltalk, although it has it's own warts, still provides the best implementation of blocks. They close over their environment, including the current 'self', which makes it painless to write blocks and not have to think about scope. The following will raise an exception: Foo := Object clone do( init := method( x := 10 ) foo := method( y := 20 block(writeln x) call block(writeln y) call ) ) Foo clone foo So what if blocks' self was set to the current method's locals, or inherited from the current method's locals? Would that work? Mike |
|
|
Re: The old block scope debateYeah.. um, I haven't coded in Io for a bit, so there's lot of errors :)
Nevermind! It should be the following, which works. Foo := Object clone do( init := method( self x := 10 ) foo := method( y := 20 block(writeln(x)) call block(writeln(y)) call ) ) Foo clone foo Mike Mike Austin wrote: > > > I've been digging into other languages again, and want to bring up the old > block scope debate. I think Smalltalk, although it has it's own warts, > still > provides the best implementation of blocks. They close over their > environment, > including the current 'self', which makes it painless to write blocks > and not > have to think about scope. > > The following will raise an exception: > > Foo := Object clone do( > init := method( > x := 10 > ) > foo := method( > y := 20 > block(writeln x) call > block(writeln y) call > ) > ) > > Foo clone foo > > So what if blocks' self was set to the current method's locals, or > inherited > from the current method's locals? Would that work? > > Mike > > |
|
|
Re: The old block scope debateYou are sending the x message to the object returned by writeln, which
is nil. Object clone do(name := "Rich"; greet := method(block(writeln("My name is " .. name)) call)) greet On Oct 3, 2009, at 11:30 AM, Mike Austin wrote: > I've been digging into other languages again, and want to bring up > the old > block scope debate. I think Smalltalk, although it has it's own > warts, still > provides the best implementation of blocks. They close over their > environment, > including the current 'self', which makes it painless to write > blocks and not > have to think about scope. > > The following will raise an exception: > > Foo := Object clone do( > init := method( > x := 10 > ) > foo := method( > y := 20 > block(writeln x) call > block(writeln y) call > ) > ) > > Foo clone foo > > So what if blocks' self was set to the current method's locals, or > inherited > from the current method's locals? Would that work? > > Mike > > > ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/iolanguage/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/iolanguage/join (Yahoo! ID required) <*> To change settings via email: mailto:iolanguage-digest@... mailto:iolanguage-fullfeatured@... <*> To unsubscribe from this group, send an email to: iolanguage-unsubscribe@... <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/ |
|
|
Re: The old block scope debateI sent this reply, but I'll try again...
Yeah.. um, I haven't coded in Io for a bit, so there's lot of errors :) Nevermind! It should be the following, which works. Foo := Object clone do( init := method( self x := 10 ) foo := method( y := 20 block(writeln(x)) call block(writeln(y)) call ) ) Foo clone foo Mike Mike Austin wrote: > > > I've been digging into other languages again, and want to bring up the old > block scope debate. I think Smalltalk, although it has it's own warts, > still > provides the best implementation of blocks. They close over their > environment, > including the current 'self', which makes it painless to write blocks > and not > have to think about scope. > > The following will raise an exception: > > Foo := Object clone do( > init := method( > x := 10 > ) > foo := method( > y := 20 > block(writeln x) call > block(writeln y) call > ) > ) > > Foo clone foo > > So what if blocks' self was set to the current method's locals, or > inherited > from the current method's locals? Would that work? > > Mike > > |
| Free embeddable forum powered by Nabble | Forum Help |