Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:49720 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32246 invoked from network); 16 Sep 2010 18:23:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2010 18:23:57 -0000 Authentication-Results: pb1.pair.com header.from=ionut.g.stan@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=ionut.g.stan@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ionut.g.stan@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:42995] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 08/AA-15036-CB0629C4 for ; Thu, 16 Sep 2010 14:23:57 -0400 Received: by bwz7 with SMTP id 7so2133069bwz.29 for ; Thu, 16 Sep 2010 11:23:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=2Rb5WS8wp4kTt1zhjKGmSY/oIKIOpL13/doyr7uoyQ0=; b=iButx74jgt89nup2GH030vQBL9QKO6SUZ5jpRl2V+d8Sbr0IyWhTH7c23geVf5Mgpj 0/GsD2CnMyFzIf4MM8JnNK8fnUx0T54guN/OsAkZAvXrovu6jF/n+iIxAd9/JbI4BdCG pwGd6LZivj91EBKnImthXlDiLMwChd+Ql0Pvk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=dVsMZFdm+0Ie+pB6clqGyi+KM1aQA/JD4BHQV8FW28Ta/zyGHMhcL8txYfFcFlRSY7 7R/KwnZtnPRJ4x7VCnJMQX7PYcEdcIPOFJohjUUzlXheMATRj8ABITbDT9vrsVCn+0eN mDfWyFHW2WKzSPUm+ww3u7CO32owLpGYbcjP0= Received: by 10.204.50.204 with SMTP id a12mr2832537bkg.117.1284661433853; Thu, 16 Sep 2010 11:23:53 -0700 (PDT) Received: from l.local ([89.36.11.205]) by mx.google.com with ESMTPS id 24sm2745967bkr.7.2010.09.16.11.23.51 (version=SSLv3 cipher=RC4-MD5); Thu, 16 Sep 2010 11:23:52 -0700 (PDT) Message-ID: <4C926083.605@gmail.com> Date: Thu, 16 Sep 2010 21:22:59 +0300 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100825 Thunderbird/3.1.3 MIME-Version: 1.0 To: internals@lists.php.net References: <39505F13-655A-43AF-941E-77750B7F7201@gmail.com> <4C8FC695.2060800@sugarcrm.com> <4C8FD72B.1070108@sugarcrm.com> <4C906333.4030204@sugarcrm.com> <7.0.1.0.2.20100915085504.17eab4d8@zend.com> <12617cf66ae07d7a2fd79a293ed69b85@beberlei.de> <4C9095D5.1050206@toolpark.com> <000001cb5511$467949f0$d36bddd0$@com> <64b4e95cac44ee297a12601d26a5453c@localhost> <4C9258C1.9080207@sugarcrm.com> In-Reply-To: <4C9258C1.9080207@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Lambdas assigned to constants. Was PHP Annotations RFC + Patch From: ionut.g.stan@gmail.com ("Ionut G. Stan") On 16/Sep/10 8:49 PM, Stas Malyshev wrote: > No, we can't have python decorators because unlike Python PHP functions > and classes aren't first-class objects. In Python, this: > > @dec2 > @dec1 > def func(arg1, arg2, ...): > pass > > means this: > > def func(arg1, arg2, ...): > pass > func = dec2(dec1(func)) > > However, you can't write equivalent code in PHP. I had the same idea regarding decorators, and I saw the same problem that you see, functions are not first-class citizens in PHP. I was wondering, though, whether the possibility to assign expressions to constants couldn't change that. Let me explain a little what I'm thinking exactly. Currently, PHP supports lambda expressions and they're pretty much as first-class citizens as possible. PHP, also supports variable functions in an attempt to make global functions look like they'd be first-class citizens. So, the following snippet isn't yet working, but AFAIK it will work in the next PHP release: function foo() { echo "foo was called"; } function bar() { return 'foo'; } bar()(); // prints "foo was called"; Now, assume I define this constant: define('foo', 'foo'); Now I can write: function bar() { return foo; } And the "foo" function will look more like a first-class citizens. But, how about being able to write: const foo = function () use ($globalVar) { }; which would be the desugaring of: function foo () { global $globalVar; } Now foo would be an instance of Closure, and would allow us to pass it around free. Does that make any sense to any of you? Is it at least possible with the current Zend Engine implementation? What problems would it pose? Getting back to decorators... Having the above syntax, we would be able to write: const func = dec2(dec1(function () { })); which can be further sugared to some decorator specific syntax. I guess the gist of my whole email is that it would be nice to get rid of the dollar sign in identifiers that designate lambda expressions. That would somehow level things up. -- IonuČ› G. Stan | http://igstan.ro