I don't have a clue how that works.. is it portable? (not that I'd actually use it in a real C program :p)
Amazing!
Name:
Anonymous2007-08-29 5:25 ID:9HFPURtO
Too bad c is fast as virgin fuck
Name:
Anonymous2007-08-29 5:32 ID:dqo1AGje
PHP's create_function and 1.5-class functions (variable functions, e.g. $a = 'strlen'; $a($b)) as well as array_map and company can make your life easier if you have to work with PHP. The syntax for create_function, or lack of, requires quote hell though, and you have no nested scoping, so all you're getting are anonymous functions. At most, you can create an inefficient read-only closure if you var_export() your outer variables into the anonymous function's code.
However, there's a problem with create_function: PHP doesn't really have anon functions, they are all namefags, and they are returned as functions with an invalid character in their name. They work for $a = create_function(...); $a($b); but they won't work if you try to use one inside another, e.g. $a = create_function(...); $b = create_function(..., "... $a($c) ...");. In order to fix this, and to simplify the creation of simple no-statement anon functions, I've created this more Pythonic function I use to spare myself of some pain:
>>1
PHP's anonymous functions are putrid. Trust me, tried using them for a real live project.
All it does is have the interpreter make a function called something gay like __LAMBDA001 and so forth. You have to assign a name to that.
They run slower than slowpoke, they are a horrible security risk since it blindly passes the input into the interpreter, they can't be GC'd well (but PHP's GC already sucks, so yeah...) and it's a bitch to get one lambda inside another.
Don't fucking bother. Just make a fucking function. Save yourself some headahces.
>>1
PHP's built-in library is putrid. Trust me, tried using it for a real live project.
All it does is have the interpreter run a function called something gay like __GETSOMEAIDS and so forth. You have to assign a name to that.
It runs slower than slowpoke, it is a horrible security risk since it blindly passes the input into the interpreter, it can't be GC'd well (because PHP's GC already sucks, so yeah...) and it's a bitch to get one script inside another.
Don't fucking bother. Just write in fucking Haskell. Save yourself some headahces.
>>21
Read my awesome >>16, I addressed half of your issues. And of course functions can't be disposed of in PHP, so you better not spawn them like fuck inside a loop.
>>25
Great! Ignoring the gaping security holes of create_function (wait, PHP is a gaping security hole), ssssslllow speed, and the chance to completely fuck your system if you make too many lambdas (seen it happen), we can now call a lambda inside a lambda.
>>35
an even better example of recursion with anonymous functions: function(n){
return (function(i){
return i==1?0:arguments.callee(i-1)+(function(){
return i==1?1:arguments.callee.caller(i-1)
})(i-1)
})(n+1)
}
Of course, you can't expect for ($i = 100000; --$i; lambda(...)); to work decently.
why not? stuff like that works just fine in javascript... var a=new Array();
for( i = 100000; --i ; (function(){ a[i] = i })() );
alert(a.length)