Re: lambda-like expressions for C



On Thu, Apr 10, 2003 at 02:06:06AM -0300, Mariano Suarez-Alvarez wrote:
> On Wed, 9 Apr 2003, Edward Peschko wrote:
> 
> > hey all,
> >
> > I was wondering if anybody knew of a lambda-like expression api for C... what I'm looking
> > for is something like:
> >
> > int variable = 15;
> > lambda ("if (_1 < 50) fprintf(stderr, \"HERE -- %d\", _1); ", variable);
> >
> > [...]
> > what I'm ultimately looking for is the ability to take this string from a file
> > (or other source), and reconfigure what the program is doing on the fly, without
> > recompiling. Ultimately, I want to use this for debugging purposes - ie: being able
> > to debug programs via configuration file without a debugger.
> >
> > Does anyone know an api like this/one that is available? If there isn't, would the glib
> > team be interested in helping design one, and integrating it into glib?
> 
> The term `lambda-abstraction' is usually used to refer to something
> different from what you want. A lambda abstraction is an anonymous function;
> they abound in functional languages, but they are even in perl (see
> perlsub's man page...)

argh. I know its in perl (I've written a couple of books on the language.) As for 'lambda
abstraction', well, that's why I said 'lambda-like', not 'lambda'. The closest thing
to this in perl is evaling an anonymous subroutine embedded in a string.

> quite a few available: s-lang, python, gnu's guile, and i'm sure if you go
> to http://directory.google.com/Top/Computers/Programming/Languages/ you'll
> find quite a few more.

These languages aren't used in 90+% of the projects out there. If this lambda-like thingy
was built, I'd use it heavily in both production and development. Especially for
debugging, as said up above. Print out the name/value pairs of all the variables 
beginning with a if they are set to less than 50? No problem. Instrument the c code so 
it uses this lambda-like class, put a conditional print statement after every possible 
assignment, and take the if clause from a file that you can maintain.

> I doubt glib is the right place to add such a thing, tho.

exactly why? fprintf does a close proximity to such a thing, and its used extremely 
heavily. I thought glib stood for 'generic lib' - and a lambda-like extension to C is 
pretty damn generic if done right.

For what its worth, Boost (the closest thing to generic libraries for C++ outside the 
STL) has such an extension (the lambda library) and they are considering adding a runtime
extension. 

Ed



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