In other words - he discovered gcc's ({ }) construct and decided to write a macros named <i>lambda</i> around it.<p><a href="http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62" rel="nofollow">http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC62</a>
Blocks, <a href="http://clang.llvm.org/docs/BlockLanguageSpec.txt" rel="nofollow">http://clang.llvm.org/docs/BlockLanguageSpec.txt</a><p>Much better solution to the problem, hopefully coming to standard GCC soon(tm).
I have not been able to work out two things here:<p>1) If I define a lambda inside a function, I cannot return the lambda from the function and use it right?<p>2) Recursive lambdas are not possible on account of the lack of recursion in C macros (not sure if that even makes sense without 1).
Isn't this a step closer to Greenspuns Tenth Rule?<p>"Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp"<p>(bar the environment/scope issue it avoids that is)
<p><pre><code> printf("I am bad and evil %p\n", ({int bad_and_evil(void){return 0;};&bad_and_evil;}));
printf("I am bad and evil2 %d\n", ({0x4FFFFFF;}));
void* result = ({void* bad_and_evil(int dummy){return 0;};&bad_and_evil;});
printf("bad and evil 3 = %p\n", result);
</code></pre>
* shudder * Getting a return value from a block, by inserting it in parantheses.
This is just too clumsy, and this is exactly why I think go will take off.<p><pre><code> package main
import "fmt"
func main() {
add := func(x int, y int) int{
return x+y
}
max := func(x int, y int) int{
if x>y {return x}
return y
}
fmt.Printf("lambda: add:%d\n",add(2,3))
fmt.Printf("lambda: max:%d\n",max(2,3))
}
</code></pre>
Although it'd be nice if you could have a ternary or something like<p><pre><code> return {x} if x>y else {y}</code></pre>