[haXe] callback and properties
Vadim Atlygin
vava at tepkom.ru
Fri Jan 19 10:13:02 CET 2007
Hi list,
hm, I think it is kind of late to change behavior of callback now.
On the other hand you can do something like
var func_arr: Array<Int->Void>
for ( i in 1...5) {
func_arr.push( callback(f, i) ); //every function will have it's
own value of i
}
which wouldn't work with normal closures without special tricks.
Best regards,
Vadim
Michael Pliskin wrote:
> Hello Nicolas,
>
> NC> Yes, that's normal. The specification of "callback" is that arguments
> NC> are evaluated when callback is constructed, not when function is called.
>
> [Bringing the discussion back to list as I think this is quite
> important question]
>
> Hmm I actually do not understand (yet) why this is useful. I got used
> to think that
> callback(f, a) is the same as function () { f(a); }
>
> but this appears to be not true. So the question is - why is that? Why
> to introduce a second kind of closure where arguments are evaluated
> when closure is created? I think this brings more confusion than value
> - one might mechanically convert
> function () { f(a); }
> to callback form because it is shorter and easier to read - and
> behaviour will change! (this is what I experienced).
>
>
More information about the Haxe
mailing list