Re: lambda-like expressions for C



in reverse order:

>I think you may have misunderstood me. I didn't mention conversion of 
>source code to instructions anywhere. The only thing I specifically 
>mentioned was that "I need to defer function evaluation".

your original email included something like this:

   lambda ("some C expression")

i interpreted the quotes as significant. sorry if that led me to
under-estimate your understanding of what you were asking.

>Ok, this is what I think it does. I think it uses expression templates 
>in a way that might allow me to generalise my current solution to the 
>problem I presented above, as I said in my last mail. If you think 
>differently, I'd be interested to hear about it. Ed's message prompted 
>me to re-read my reference on expression templates - Vandevoorde & 
>Josuttis - and, oddly enough, they actually cite the Boost Lambda 
>library as an example of the use of expression templates.

i prefer SigC++, which does the same thing and is very slightly more
powerful. it might do that kind of thing you mean, in that you can
wrap up a function call plus any number of arguments (of any type),
and it will generate a closure for you that can be "executed" later:

   void some_function (int arg1, void *arg2, float arg3, some_type_t* arg4);

   /* ok, package up a "call to some_function() with some arguments" */

   SigC::Slot slot (some_function, 1, ptr, 32.67, some_type_ptr);

   /* now pass the closure to another function */
   
   some_other_function (slot);

then, within some_other_function:
      
      some_other_function (SigC::Slot slot) 
      {
           slot(); // executes some_function with the arguments you
		   // supplied.
      }

its a very powerful mechanism but it relies 100% on C++ templates for
its implementation. doing it in C would very very painful, and would
require either marshallers like the GObject system or the
pre-processor working very hard.

--p



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]