Re: Re: Closure local return
| From: | mathieu.suen | Date: | Tue, 04 May 2010 07:24:20 +0000 |
| Subject: | Re: Re: Closure local return | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-48186@lists.php.net to get a copy of this message | ||
On 05/03/2010 11:34 PM, Tjerk Anne Meesters wrote:
On Mon, May 3, 2010 at 11:42 PM, Christian Schneider <cschneid@cschneid.com> wrote: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.mathieu.suen wrote: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.define scope. For example. $findedElment = $myList->selectIfAbsent($fooo, function(){May be it could be interesting to have a syntax for returning from thereturn 'No item founded'; //Retrun from the define scope}) //Do somthing with $findedElment
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; } }
-- Mathieu Suen- Chris -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php