Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38344 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67210 invoked from network); 18 Jun 2008 10:09:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2008 10:09:22 -0000 Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 72.14.220.152 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 72.14.220.152 fg-out-1718.google.com Received: from [72.14.220.152] ([72.14.220.152:64150] helo=fg-out-1718.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 63/B9-03518-FCED8584 for ; Wed, 18 Jun 2008 06:09:20 -0400 Received: by fg-out-1718.google.com with SMTP id 16so105354fgg.23 for ; Wed, 18 Jun 2008 03:09:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to :to:subject:cc:in-reply-to:mime-version:content-type:references; bh=SWPos0md33VjWdtWWkGIynrp+tLKALZ6UYazWu8U2vc=; b=ShiXZheAhNJpqagITT0VuQLlsu9TnSNz0v8aeXxXWcnicG+hFExH5dy5B76cUVD3RB Jr/V7/Sd/YTzKs90JoVCdrcGoRkxO4SapU9Pk8ej2DUnn7zoFOV1i58SZnEVRl8VKCSP +jRQq98BFHiOXXk656irar6PUCMMe+JTNbQus= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:cc:in-reply-to :mime-version:content-type:references; b=eNuYO0akozHwskYqQFy9ggBlgSo1PXMDT42wgu8dwj/9ZYQaElDnkyf1lKJOnQaX6S 9Zm2aaBHcKFXLoFDci9dqt5mG5Ua+jGzWvSA3odD5gRynfS2FBPqB5uS9HnOa4rUjz/e /Po1LK8IIFyfRNhVCyAZZ3Zl/Zl1hAOWf9bDo= Received: by 10.86.98.10 with SMTP id v10mr510656fgb.39.1213783755964; Wed, 18 Jun 2008 03:09:15 -0700 (PDT) Received: by 10.86.97.3 with HTTP; Wed, 18 Jun 2008 03:09:15 -0700 (PDT) Message-ID: <10845a340806180309j1d666ff0g306af623bfb79381@mail.gmail.com> Date: Wed, 18 Jun 2008 11:09:15 +0100 Reply-To: RQuadling@GoogleMail.com To: "Gwynne Raskind" Cc: "PHP Developers Mailing List" In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_18620_19827291.1213783755948" References: <4856A547.3080801@gmx.net> <698DE66518E7CA45812BD18E807866CE01B11811@us-ex1.zend.net> Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: rquadling@googlemail.com ("Richard Quadling") ------=_Part_18620_19827291.1213783755948 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/6/18 Gwynne Raskind : > On Jun 18, 2008, at 2:36 AM, Alexey Zakhlestin wrote: > >> 1) I am not sure that the current semantics of the "lexical" keyword is >>> great in all cases. Is the reason why you don't allow by-value binding so >>> that we don't have to manage more than one lambda instance per declaration? >>> >> by-reference binding is much closer to other languages symantics. I >> guess, that was the main reason Christian chose it. >> "by-value" may still exist, if people find, that they need it, but >> only in addition, please. >> >> lambda has to reflect changing state of context, to be truly useful >> > > In Lua, the language in which I've seen the most of closures and lambda, > lexical scoping is handled this way: > > someVariable1 = "asdf"; > someVariable2 = "jkl;"; > SomeFunction = function() > local someVariable2 = "1234"; > > print someVariable1.." "..someVariable2.."\n"; > end > print gettype(SomeFunction).."\n"; > SomeFunction(); > someVariable1 = "qwer"; > someVariable2 "0987"; > SomeFunction(); > > The resulting output of this code fragment would be: > function > asdf 1234 > qwer 1234 > > The Lua interpreter handles this by resolving variable references as > they're made; "someVariable1" is looked up in the closure's scope and not > found, so the interpreter steps out one scope and looks for it there, repeat > as necessary. Once found outside the closure's scope, something similar to > the proposed "lexical" keyword happens. Closures and lexical variables can > be nested this way, to the point where a single variable in a sixth-level > closure could still have been originally found in the global scope. > > I'm not sure this would work for PHP, I'm curious what others think. > > Of course, that fragment does a very poor job of showing off the extreme > flexibility of Lua with regards to functions and scoping, but hopefully it > illustrates the concept. > > -- Gwynne, Daughter of the Code > "This whole world is an asylum for the incurable." > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Is "nested scope" just the same as "namespace" in this regard? -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" ------=_Part_18620_19827291.1213783755948--