On 05/03/2010 11:34 PM, Tjerk Anne Meesters wrote:
On Mon, May 3, 2010 at 11:42 PM, Christian Schneider
<cschn...@cschneid.com> wrote:
mathieu.suen wrote:
May be it could be interesting to have a syntax for returning from the
define scope.
For example.
$findedElment = $myList->selectIfAbsent($fooo, function(){
return 'No item founded'; //Retrun from the define scope
})
//Do somthing with $findedElment
I think you actually misunderstand the difference in
http://en.wikipedia.org/wiki/Closure_%28computer_science%29#Differences_in_semantics
The way I read if the difference is wether it returns from the closure
function or the surrounding function *calling* it. Not the *defining* scope.
Mathieu is right in that it would return from the defining scope, but
it's important to note that when the closure is called the function
that defined the closure is still on the stack.
Consider the following example:
function f() { return function() { return; } }
$c = f();
$c();
If the semantics of Smalltalk were to apply, this would give an error,
because it's impossible to return from f() when the closure is being
called.
And no, it doesn't make sense in the PHP context IMHO.
I second that ;-) In terms of clarity I find that the ECMAScript
implementation is much clearer.
Of course ECMAScript has the same semantic than PHP. :)
(for this particular point, I don't mean for the rest)
May be one could fink of a different syntax:
function() { return-from-def-scope; }
And that would also remove the ambiguity in your example:
function f() { return function() { return-from-def-scope; } }
- Chris
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
-- Mathieu Suen