Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38440 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57824 invoked from network); 20 Jun 2008 00:57:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2008 00:57:38 -0000 Authentication-Results: pb1.pair.com header.from=stas@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=stas@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: stas@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.162] ([212.25.124.162:58519] helo=mx1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/80-54491-1800B584 for ; Thu, 19 Jun 2008 20:57:38 -0400 Received: from us-ex1.zend.com ([192.168.16.5]) by mx1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 20 Jun 2008 03:57:45 +0300 Received: from [192.168.16.110] ([192.168.16.110]) by us-ex1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Jun 2008 17:56:01 -0700 Message-ID: <485B0014.9090901@zend.com> Date: Thu, 19 Jun 2008 17:55:48 -0700 Organization: Zend Technologies User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Alexander Wagner CC: internals@lists.php.net, Christian Seiler References: <4856A547.3080801@gmx.net> <698DE66518E7CA45812BD18E807866CE01B70D73@us-ex1.zend.net> <48596C9E.2080605@gmx.net> <200806200146.25898.waqner@gmx.net> In-Reply-To: <200806200146.25898.waqner@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 20 Jun 2008 00:56:01.0677 (UTC) FILETIME=[68D133D0:01C8D270] Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: stas@zend.com (Stanislav Malyshev) Hi! > First, a comment from haskell-land: > http://www.haskell.org/pipermail/haskell-cafe/2008-June/044533.html > http://www.haskell.org/pipermail/haskell-cafe/2008-June/thread.html#44379 Thanks for the links, very interesting. Even a couple of comments in the thread going beyond "PHP sucks" and really discussing the matter. :) Best account is this: * A closure must only keep alive the varables it references, not the whole pad on which they are allocated [Check] * A closure must be able to call itself recursively (via a higher-order function typically) [Check, since you can use variable you assigned closure to inside the closure, if I understand correctly] * Multiple references to the same body of code with different bindings must be able to exist at the same time [Check] * Closures must be nestable. [Dunno - does the patch allow nesting and foo(1)(2)?] > Getting the same behaviour out of PHP should not be as difficult as this: Well, I don't see any other way if you use references. Variables _are_ mutable in PHP. You could, of course, use copies, but then you'd lose ability to update. Maybe if we drop "lexical" and use Dmitry's proposal of $arr[$i] = function () ($i) { return $i; }; where ($i) would be copy, (&$i) would be by-ref, then it'd be easier to control it. I know function()() is weird, but not everybody likes lexical either :) Maybe we can do lexical &$y, but that looks weird too... > Of course this would make lexical behave quite differently from global in this I wouldn't spend too much thought on making lexical work like global. global is for different purpose (and with $GLOBALS is obsolete anyway :) -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com