Re: lambda-like expressions for C



Paul Davis wrote:

when you write

     if (i < 50) fprintf (stderr, "something\n");

this expression is converted by the compiler into machine code. when
the processor actually executes it, it is simply marching through a
series of low-level instructions that cause it to do certain basic
things.

Therein lies the problem. How do you change the program's behaviour at runtime, without using an interpreted language, or attempting to compile on the fly as you suggest? It can be done, but C++ makes it very difficult.

There are (very) good reasons to do this, other (compiled) languages do it, and I have C++ code that does exactly this. In my case, I need to defer function evaluation until some later point in the code. C++ makes this *very* difficult, but I can get some of the way there by storing references to the deferred function's actual parameters, and what the function needs to do, so that it can all be executed at a later time. If I could also get the deferred function from another file at runtime, as Ed wanted, that would be great, but I can't. I found the Boost lambda reference very useful - I may be able to use their expression template mechanism to get a bit further in what I need to do.

so, as i said, either i am misunderstanding you or you don't seem to
grasp this basic level of program execution.

Here's another way of looking at it:

The machine code sequentially reaches a certain address. However, at this address, it finds instructions which should not be executed immediately, but which specify some actions for later execution. Call it an anonymous function, if you want. Possibly much later, it finds it has to evaluate the statements in the anonymous function, from a different context.

Evan




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