Zeev,

My only gripe with create_function() is the inherent "dirt" involved in handing a code-containing string to a function. I've been living in the app development world for some time now, so my example stash is clean out, but my notion is that, for folks who have a real, novel application for an anonymous lambda function, the benefit of having it "fit in" with the rest of the language would be at least tangible. Granted, everything is effectively run-time in the PHP world, but the ability to employ regular syntax for these anonymous functions could be quite handy. Things like line numbers, code formatting, highlighting, and annotations would be as relevant as in "regular" code.

I agree that we shouldn't look at the laundry list of every other language feature and include them all, but better support for anonymous functions would surely help some folks. That said, the ability to generate and run code from a string in one pass is handy, but maybe it's not just what the doctor ordered in some cases. I've always seen PHP as an enabling technology, allowing people to solve their problems in very novel and fitting ways. I'd hate to see that philosophy suffer when the problem space lends itself to functional programming.

Thanks,
-Noah


On Aug 23, 2005, at 3:01 PM, Zeev Suraski wrote:

At 09:18 23/08/2005, Michael Walter wrote:

On 8/22/05, Stanislav Malyshev <[EMAIL PROTECTED]> wrote:
> MB>>> * Anonymous functions. The real stuff, not just some odd string
> MB>>> passed to create_function().
> MB>>
> MB>>There were some others already asking for this, maybe we should at least
> MB>>give it a thought if it is doable at all, anybody?
>
> Just out of curiosity, what's bad in create_function and how "real" ones
> should be different?

"Real" anonymous functions (as in, closures) should be able to capture
variables from its lexical environment, e.g.:


create_function() accepts a string, and that string is constructed with full access to the lexical scope of the creating function, so I'm not exactly sure how it's different. My ML/LISP memory fails me.


  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.


Since when do we consider moving towards LISP a good thing? :)

For those odd ends where you really need that, create_function() can do the job for you just as well (before anybody complains that it's cumbersome - GOOD, it's supposed to be, you're not supposed to be creating functions on the fly unless you absolutely have to).

Zeev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to