Re: On closures and lamdba
| From: | mathieu.suen | Date: | Wed, 24 Feb 2010 07:38:47 +0000 |
| Subject: | Re: On closures and lamdba | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47044@lists.php.net to get a copy of this message | ||
Stanislav Malyshev wrote:
Hi!I would rather say that PHP have both. Closure is just a subset of lanbda. You say that a lambda is a closure whenever the lambda capture variable from its outer scope. You even have a special syntactic form to declare a lambda to be a closure, the keyword "use". -- Mathieu --My question is not so much about implementation it is about language. I have noticed quite a few times now that PHP developers use the word "closure" when I would prefer "lambda".Everybody on the internet knows that Wikipedia is the ultimate source of knowledge, and it says: In computer science, a closure is a first-class function with free variables that are bound in the lexical environment. Such a function is said to be "closed over" its free variables. I think this describes what PHP is doing.However, in the PHP manual as well as on this list, you seem to be saying "closure" === "anonymous function" (which is what I'd rather see called lambda).This is not entirely correct, you are right. There's a difference between anonymous function and closure, though in practice in PHP anonymous functions are closures (though some of them are rather trivial ones with no variables to "close over") and that's now the only way to do closure in PHP (i.e. you can't have non-anonymous closure function).