Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47007 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 3943 invoked from network); 21 Feb 2010 00:47:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2010 00:47:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=webmaster@keryx.se; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=webmaster@keryx.se; sender-id=pass Received-SPF: pass (pb1.pair.com: domain keryx.se designates 208.69.121.33 as permitted sender) X-PHP-List-Original-Sender: webmaster@keryx.se X-Host-Fingerprint: 208.69.121.33 supavet.nexcess.net Received: from [208.69.121.33] ([208.69.121.33:46371] helo=supavet.nexcess.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/9A-29373-B92808B4 for ; Sat, 20 Feb 2010 19:47:26 -0500 Received: (qmail 9247 invoked by uid 108); 20 Feb 2010 19:47:19 -0500 Received: from unknown (HELO z61p.keryx.se) (gunther@keryx.se@90.228.192.235) by supavet.nexcess.net with AES256-SHA encrypted SMTP; 20 Feb 2010 19:47:19 -0500 Message-ID: <4B808294.1070801@keryx.se> Date: Sun, 21 Feb 2010 01:47:16 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20100120 Fedora/3.0.1-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.1 MIME-Version: 1.0 To: internals@lists.php.net References: <4B54FC87.8070106@zend.com> <4F.56.22457.408955B4@pb1.pair.com> <4B55D850.8000604@zend.com> In-Reply-To: <4B55D850.8000604@zend.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] On closures and lamdba From: webmaster@keryx.se (Keryx Web) 2010-01-19 17:05, Stanislav Malyshev skrev: >> I honestly don't see func()()()() make anything better in the >> world of a PHP programmer. > > You probably don't use closures, right? Sorry for kidnapping a thread, bit it was this message that got me thinking about raising the issue in earnest. I'm also a little late to the party, replying to amonth old message, since I do not have time to read this list as often as I'd like. My question is not so much about implementation it is about language. I have noticed quite a few times now that PHP developers use the word "closure" when I would prefer "lambda". In discussions about JavaScript (where I have spent most of my time the last couple of years) the word "closure" is never used outside the context of inherited scope, AFAIK. A few examples:
Two one sentence summaries: * a closure is the local variables for a function - kept alive after the function has returned, or * a closure is a stack-frame which is not deallocated when the function returns. (as if a 'stack-frame' were malloc'ed instead of being on the stack!)
A closure takes place when a function creates an environment that binds local variables to it in such a way that they are kept alive after the function has returned. A closure is a special kind of object that combines two things: a function, and any local variables that were in-scope at the time that the closure was created.
In my line of work I have read about 10 books on JavaScript the last couple of years, including the works of all big names like D. Crockford, John Resig, Nicholas Zakas, etc. They all describe closures in this fashion. However, in the PHP manual as well as on this list, you seem to be saying "closure" === "anonymous function" (which is what I'd rather see called lambda). This difference in the use of words is a bit confusing I would say. One may also note that in JavaScript closures exists even with named functions, i.e. it does not need to be anonymous. Maybe this discussion belongs on the documentation list, but I wanted the reach the core developers, since you are the guys (and gals) that have produced the features and set the language. If I am out of line, please let me know and I will take my questions elsewhere. Oh, yes, the question: Wouldn't you agree that it is better for PHP to use the word closure as it is being used in the JavaScript community? -- Keryx Web (Lars Gunther) http://keryx.se/ http://twitter.com/itpastorn/ http://itpastorn.blogspot.com/