Stanislav Malyshev wrote:
Hi!

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).

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

--


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

Reply via email to