Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48185 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52239 invoked from network); 4 May 2010 07:08:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 May 2010 07:08:31 -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:39139] helo=mail.easyflirt.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/40-50448-DE7CFDB4 for ; Tue, 04 May 2010 03:08:30 -0400 Received: from [192.168.0.51] (office.easyrencontre.com [78.155.152.6]) by mail.easyflirt.com (Postfix) with ESMTPSA id 34522636F89 for ; Tue, 4 May 2010 09:08:26 +0200 (CEST) Message-ID: <4BDFC7E9.1070408@easyflirt.com> Date: Tue, 04 May 2010 09:08:25 +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> <4BDEF1AF.70704@easyflirt.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------080502010805040607040003" Subject: Re: [PHP-DEV] Re: Closure local return From: mathieu.suen@easyflirt.com ("mathieu.suen") --------------080502010805040607040003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 05/03/2010 06:03 PM, Etienne Kneuss wrote: > On Mon, May 3, 2010 at 5:54 PM, 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. >>> >>> And no, it doesn't make sense in the PHP context IMHO. >>> >>> - Chris >>> >>> >>> >> "returns from the closure function" >> To go were? >> >> I had maintain a smalltalk compiler. >> I did not misunderstand the difference. >> >> The Common Lisp implementation is the more explicit one. >> For exemple: >> >> (defun eval-l1 (fct) (funcall fct)) >> (defun bar (x) (eval-l1 #'(lambda () (return-from bar 45))) >> x) >> >> (bar 23) -> 45 >> >> When funcall is apply you do not return from eval-l1. You return from bar. >> Which is the defining scope of the lanbda. >> > So > > $a = function() { return; } > > $a(); > echo "end"; > ?> > > would it be an infinite loop? would it print end? > > what about: > > function foo($c) { > bar($c); > echo "f"; > } > > function bar($c) { > $c(); > echo "b"; > } > $c = function() { return; } > > foo($c); > > what would it print? "f"? "fb" ? nothing? > This is an interesting question. It depend on whether you consider your lanbda as a continuation. The other safe possibility is to generate an error when you evaluate a lambda were the context has escape which is the case in your example. But a would not change the semantic of "return" just chose an other keyword. $c = function() { return-from-def-scope; } > Please, if you want to propose design changes, make a decent proposal > first, add some examples, not simply "what if PHP did". > No big deal, I don't want to make any proposition, I am just asking. I am not using PHP as a language for fun. > Best, > >> >> -- Mathieu Suen >> >> >> -- Mathieu Suen --------------080502010805040607040003--