passing auxiliary data to call-backs and closures (was: pointer)

passing auxiliary data to call-backs and closures (was: pointer)

Post by Fred » Sat, 18 Jul 2009 03:20:50



> >to the callback functions. I don't consider variables declared >>>>at file scope to be reasonable in this context.) >> >> This is one place, where Java programming really shines.> >> > In Java, you can't pass a call-back method to another metho>
> at all, you can only pass a call-back object. So, say y>u
> have a c>ll> >
> void qsort( base, nmemb, size, compar>);> >
> , then omparmust be an object, and qsort will cal> its
> ompare>et>od.
>
> Now, what has this to do with auxilia>y >ata?
>
> An object has to be construc>ed> like
>
> compar = new Compa>( >.. );
>
> , and there, at the ellipsis "...", you can pu> whatever
> auxiliary data you can dream of into your com>ar object.
> No need for qsort to be aware of it, no mea>s for qsort
> to get in the>wa> of this.
>
> And this might be one reason against > certain kind
> of cl>su>es in Java.
>
> As soon as a method accepts a closure and >n the case that
> this is implemented in a way where a clo>ure is a kind of
> method, but /not/ a fully fledged object> this way to pass
> auxiliary data >on't work anymore.
>

Trivial to do this in C. Just pass an array of structs to qsort,
and a comparison method that knows how to compare two different
instances of that struct.
The struct can contain anything.
Fred K.
 
 
 

passing auxiliary data to call-backs and closures (was: pointer)

Post by Roedy Gree » Sat, 18 Jul 2009 03:34:36

On 16 Jul 2009 17:48:52 GMT, XXXX@XXXXX.COM (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :


the official name is a "delegate". See
http://www.yqcomputer.com/
http://www.yqcomputer.com/
--
Roedy Green Canadian Mind Products
http://www.yqcomputer.com/

"For reason that have a lot to do with US Government bureaucracy, we settled on the one issue everyone could agree on, which was weapons of mass destruction."
~ Paul Wolfowitz 2003-06, explaining how the Bush administration sold the Iraq war to a gullible public.