lambda defs in C

K. Richard rich at rexago1.UUCP
Thu Feb 6 03:39:53 AEST 1986


I often find myself creating highly localized register variables in an
attempt to synthesize common sub expression optimization:

	{
		register  char _q = *((x.y)->z);

		if (_q == 'a' || _q == 'b' || _q == 'c') { ...

I also want to return values from arbitrary expressions like a for loop.
Lisp has something called a lambda definition which is something like
a local temporary function definition. Sort of like:

	if ( lambda int f(register char _q = *((x.y)->z)) {
			return(_q == 'a' || _q == 'b' || _q == 'c');
		}	/* end of lambda def */ ) { ...

or

	x = lambda int f() {
		for (...) {
			...
			return(some expression);
			...
		}	/* for */
	}	/* lambda */

So, academically, if we were to add a simlar feature to a new dialect of C,
or to construct a pre-preprocessor for ansii C (a la C++), what problems
do you see?

K. Richard Magill



More information about the Comp.lang.c mailing list