Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54354 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78184 invoked from network); 4 Aug 2011 12:40:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 12:40:07 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.42 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.218.42 mail-yi0-f42.google.com Received: from [209.85.218.42] ([209.85.218.42:36322] helo=mail-yi0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 88/AA-18399-4239A3E4 for ; Thu, 04 Aug 2011 08:40:06 -0400 Received: by yih10 with SMTP id 10so1138110yih.29 for ; Thu, 04 Aug 2011 05:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=gP58QDl4jFODaz5TiZqgU9HKYbJ4oNSMdaEyLbGyDFc=; b=d65p3D+9VLgNNEASBy89gaJdspH66yBTmatzxesJQyaouV8QJknHzU61VYyrJyKTkv uLRBlunqQgAApGZWHF6AY8Hu/V2C95i6Xt5akyQ7752gs3byoIpEJ951R97bVn9L5771 1v+fSoEEOJ60V3MDZ/mjra05Afp7KJOM3YJlY= Received: by 10.236.193.9 with SMTP id j9mr1043938yhn.6.1312461602132; Thu, 04 Aug 2011 05:40:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.147.168.19 with HTTP; Thu, 4 Aug 2011 05:39:42 -0700 (PDT) In-Reply-To: <1312457975.1541.7.camel@guybrush> References: <4E3A48F2.4000503@lerdorf.com> <4E3A8014.1030503@rotorised.com> <1312457975.1541.7.camel@guybrush> Date: Thu, 4 Aug 2011 14:39:42 +0200 Message-ID: To: =?UTF-8?Q?Johannes_Schl=C3=BCter?= Cc: Ryan McCue , Rasmus Lerdorf , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] An implementation of a short syntax for closures From: linepogl@gmail.com (Lazare Inepologlou) > ... ( $x ) =3D> $x + 1 for example would be ambiguous if used in an array= definition, but is otherwise the best in terms of readability. > ... people wanted an easy way to grep for function declarations A new and unique operator (like the |=3D> I have proposed) is a solution that works because: 1. A lambda expression can be part of other expressions, like arrays. Therefore, we cannot reuse =3D>, or ->. 2. Multiple lambda expressions can be chained. The operator must have very low precedence and it be right associative. 3. Lambdas should be grep-able. For those who would like to try other syntaxes that could work in PHP, I suggest a simple and creative way to approach this. All we need is 3 operators: OP_A args OP_B lexical_vars OP_C expr Operator OP_C ought to have the above properties (unique, low precedence, right associative). On the other hand there are no restrictions about OP_A and OP_B and we can reuse existing ones as long as they don't conflict and they look nice. :-) Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2011/8/4 Johannes Schl=C3=BCter : > On Thu, 2011-08-04 at 21:18 +1000, Ryan McCue wrote: >> Lazare Inepologlou wrote: >> > Thank you for your interest. This is just a proposal that I have teste= d and >> > works. Of course, the final syntax can be different. Syntax is always = a >> > matter of taste :-) >> >> As much as I love the idea, I have to agree that using | doesn't really >> make sense here and actually makes the readability worse, IMO. However, >> I can't really think of a better operator. ( $x ) =3D> $x + 1 for exampl= e >> would be ambiguous if used in an array definition, but is otherwise the >> best in terms of readability. > > If you go there you can also allow more complex statements and re-use > symbols used to group statements, using a syntax like > > =C2=A0 =C2=A0 ( $x ) { $x + 1; } > > Oh wait - now we've reached a point which was mentioned in this thread > already "allow to drop the function keyword". > > Back when I proposed to drop "function" a key argument was that people > wanted an easy way to grep for function declarations. I accepted the > validity of that concern and think this might be a case here, too. The > difference of these few characters is not that much but the keyword > gives a clear guidance what's going on, else you might end up with a > long list of random characters next to each other ... > > johannes > > >