At 18:47 23/08/2005, Dmitry Stogov wrote:
> function adder($a) {return function($b) {return $a+$b;}}
> function index($i) {return function($a) {return $a[$i];}}
>
> I'm sure you can think of useful examples.
I like this syntax and expected behavior.
The only problem is implementation.
That's far from being the only problem. Implementation is just about the
last thing we should be thinking about when we deal with stuff like that.
This syntax is unclear, much less verbose than create_function() and mixes
runtime & compile time together. It's very LISPish, and there's nothing
positive about that.
Anonymous functions those don't capture variables from lexical scope can be
compiled once at file compile time, instead of evaluating in
create_function(). But I don't see how it can be done with variable
capturing.
Again, not only does create_function() allow you to do that easily, but
it's also a heck of a lot clearer what comes from where.
function index($i)
{
return create_function('$a', "return \$a[$i];");
}
For the record, I think that the notion of 'function factories' is so
rarely useful in and so alien to PHP that we shouldn't be wasting time on
it, let alone consider introducing language constructs to support it.
Zeev
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php