Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48186 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54398 invoked from network); 4 May 2010 07:24:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2010 07:24:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=mathieu.suen@easyflirt.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mathieu.suen@easyflirt.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain easyflirt.com designates 91.199.255.56 as permitted sender) X-PHP-List-Original-Sender: mathieu.suen@easyflirt.com X-Host-Fingerprint: 91.199.255.56 python-06.easyrencontre.com Linux 2.6 Received: from [91.199.255.56] ([91.199.255.56:57874] helo=mail.easyflirt.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/A0-50448-8ABCFDB4 for ; Tue, 04 May 2010 03:24:25 -0400 Received: from [192.168.0.51] (office.easyrencontre.com [78.155.152.6]) by mail.easyflirt.com (Postfix) with ESMTPSA id EABCC636F89 for ; Tue, 4 May 2010 09:24:20 +0200 (CEST) Message-ID: <4BDFCBA4.1030700@easyflirt.com> Date: Tue, 04 May 2010 09:24:20 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: internals@lists.php.net References: <4BDEC91F.9080305@easyflirt.com> <4BDEEEDA.1050806@cschneid.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------030800090008060205080202" Subject: Re: [PHP-DEV] Re: Closure local return From: mathieu.suen@easyflirt.com ("mathieu.suen") --------------030800090008060205080202 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 05/03/2010 11:34 PM, Tjerk Anne Meesters wrote: > On Mon, May 3, 2010 at 11:42 PM, Christian Schneider > 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 --------------030800090008060205080202--