Content deleted Content added
Line 27:
:* support for closures (see above) (not in C)
: I don't think an eval function, Lisp macros, C macros, C++ templates, code generation, or Java / .NET reflection are features that belong in this list. As remarked above it would be good to explicitly make this clear was well. [[User:Rp|Rp]] ([[User talk:Rp|talk]]) 08:17, 7 April 2008 (UTC)
----
: If your using Apple's version of C then you can use their new block syntax which adds closures and runtime blocks to the C language. Apple has submitted their change to the C language to be added to the standard (its currently implemented on the the llvm-gcc and clang C compilers. These blocks/closures work in C, C++ and Objective-C
: Here is an example of what they look like in C:
<code>
void EvalFuncOnGrid( float(^block)(float) ) {
int i;
for ( i = 0; i < 5 ; ++i ) {
float x = i * 0.1;
printf("%f %f", x, block(x));
}
}
void Caller(void) {
float forceConst = 3.445;
EvalFuncOnGrid(^(float x){ return 0.5 * forceConst * x * x; });
}
void main(void) {
Caller();
}
</code>
: These blocks can be treated as first class functions, they have a dynamic binding, can be passed around at run time and automatically track references to variables used inside that are declared outside of their scope, thus they act as true closures. The complete specification can be found here: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1370.pdf
: [[Special:Contributions/75.143.82.88|75.143.82.88]] ([[User talk:75.143.82.88|talk]]) 03:29, 3 August 2009 (UTC)
== Does Ruby really have first class functions? ==
|