[haXe] blocks and yield?
blackdog
blackdog at ipowerhouse.com
Sat Apr 7 00:02:23 CEST 2007
On Fri, 06 Apr 2007 18:40:49 +0200
Nicolas Cannasse <ncannasse at motion-twin.com> wrote:
> > hi list
> >
> > It'd be nice to have the rubyish block and yield construct in haxe,
> > it's just a bit of 'syntactic sugar' as it seems to me all the
> > requisite plumbing exists.
> >
> > obj.method() { x -> block }
>
> For blocks, there is a problem of syntax, since using { } will lead to
> major conflicts.
>
i'm not stuck on {} :), how about a double {{ .... }} ?
> For "yield", this need appropriate VM support which is not available
> either in Flash or JS.
>
yeild is really just calling a closure, no? I guess i'm thinking much
more of the groovy implementation which is much closer to haxe than
ruby is
java doesn't have a yield in the vm either (as far as i know), but
groovy does it like this
public method(int x,Closure c) {
// snip
c.call(myparam);
// snip
}
called with
obj.method(1) { p ->
println p
}
OR
obj.method(1,{p-> println p})
the block/closure is tacked onto the end of the param list.
in haxe within the called method it could know it's dealing with a
pointer to a function in the same way, and have an anonymous function
passed as the the last parameter,
in haxe
public function generate(x:Int,f:Dynamic->Void) {
f(myparam);
}
called with
obj.generate() {{ x ->
trace(x)
}}
the groovy way is not intrinsic to the VM it is syntactic sugar on the
calling side, and works very well.
if you're interested here's some groovy info
http://groovy.codehaus.org/Closures
> Nicolas
>
More information about the Haxe
mailing list