Alan M. Carroll wrote:
Using the example in your other e-mail, a solution is
find_if(as.begin(), as.end(), boost::bind(std::bitwise_and<int>(), SOME_FLAG, boost::bind(&A::wee, _1)));
Anonymous functions and classes are nice. LISP, of course, did it best :-). The closest approximation of this in modern languages is actually in Perl. In Perl, any place you need a code/function pointer, you can write an anonymous function instead of using an existing one. This anonymous function is identical to any other function, it just doesn't have a name (and in fact, you could give it a name later, if you really wanted). It is definitely a very powerful language feature and a lot of the bind / lambda work is intended to support as much of that as possible.
I suspect that we're not seeing change in this area because the C++ grammar is already extremely hard to parse and rather cantankerous. Adding this kind of feature might well push it over in to unusablity. A more uniform concept of "code block" as the chunk of stuff enclosed by curly braces would help, but you still have the problem of argument declaration. Perl solves that by having only one argument style so explicit specification is not needed. LISP solved it by embedding the argument declarations inside the code block. C++, unfortunately, puts argument declarations outside the code block while not having a keyword to indicate a function declaration (perhaps, finally, a use for "entry"?).
At 11:04 AM 9/21/2005, you wrote:
Hello all,
What interests me is the anonymous methods / class style syntax that Java offers. I've played with it myself, and it seems nice, and one of the proponents in the afore mentioned flame war advocates it.
What is the thinking behind not introducing such syntax into C++? What's wrong with: std::for_each ( as.begin , as.end() , bool some_function_keyword(A& a) { return a.wee() & SOME_FLAG; } );
I don't know what a good function keyword name would be. Obviously: fn, function, lambda are in common use everywhere (and fn is too short for a C++ keyword! :D) Reuse 'inline'?