Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54341 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32100 invoked from network); 4 Aug 2011 08:53:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 08:53:42 -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:32813] helo=mail-yi0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/62-18399-61E5A3E4 for ; Thu, 04 Aug 2011 04:53:42 -0400 Received: by yih10 with SMTP id 10so1042805yih.29 for ; Thu, 04 Aug 2011 01:53:39 -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; bh=WRtFkKNWxE4QIOkXDbgHU6Dks/1CyOHrE7UB0gmXdOk=; b=CdR8aqoEkOTI6SuesvLiN8jbb+SNbE7eAGGb3BSrRA3rMryTU2CBU+zdSI0i7LKF1N JtCaPhcIYmWvja3QEfAguHx+Nbm9u50Dr+dsy2rN5urvVSr42ZCGb6s9WMEf8kbqnw4u eQhfUpYAhY82LAmiKFNubt1c8ROsU8346gpkM= Received: by 10.236.193.97 with SMTP id j61mr736765yhn.207.1312448019173; Thu, 04 Aug 2011 01:53:39 -0700 (PDT) MIME-Version: 1.0 Received: by 10.147.168.19 with HTTP; Thu, 4 Aug 2011 01:53:19 -0700 (PDT) In-Reply-To: <4E3A48F2.4000503@lerdorf.com> References: <4E3A48F2.4000503@lerdorf.com> Date: Thu, 4 Aug 2011 10:53:19 +0200 Message-ID: To: Rasmus Lerdorf Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=20cf30563c0bf80f6d04a9aa1d27 Subject: Re: [PHP-DEV] An implementation of a short syntax for closures From: linepogl@gmail.com (Lazare Inepologlou) --20cf30563c0bf80f6d04a9aa1d27 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Good morning Rasmus, Thank you for your interest. This is just a proposal that I have tested and works. Of course, the final syntax can be different. Syntax is always a matter of taste :-) > it is only useful in one limited type of trivial closure usage This trivial usage is actually the most common one. A single-return closure can be used for sorting, mapping, filtering, lifting, folding, comparing, validating, formatting, lazy-loading etc. which cover the majority of the tasks a PHP programmer does everyday. The popular LINQ library is just an example of the power of this kind of closures. The only case that these closures are not useful is asynchronous (event-driven) programming. However, PHP is single threaded and usually delegates the user interface to javascript, and therefore, two major needs for asynchronous programming are eliminated. > In PHP we try really hard not to invent new unfamiliar syntax. I have done some research before posting and it seems that the proposed syntax is not at all uncommon. For example, here is the same comparer written in a variety of languages: Proposed for PHP: | $x , $y |=3D> $x - $y C#: ( x , y )=3D> x - y Haskell: \ x y -> x - y Python: lambda x y: x - y OCaml, F#: fun x y -> x - y StandardML: fn x y =3D> x - y There are many similarities here. In all of the above examples, there is no return and no curly brackets. In addition, all expressions begin with a token and separate the arguments from the returning expression with another token. Kind regards, Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2011/8/4 Rasmus Lerdorf > On 08/04/2011 12:08 AM, Lazare Inepologlou wrote: > > $add =3D | $x |=3D> | $y : $x |=3D> $x+$y; > > This does not seem to match the syntax of any language I know of so > people are going to have a hard time figuring out what this does. It's > not even clear that |=3D> is a new operator there due to the dangling |, > which as you say conflicts with the regular | operator. Plus it is only > useful in one limited type of trivial closure usage. > > In PHP we try really hard not to invent new unfamiliar syntax. We try to > stick with things that have some basis in either the existing syntax or > in other popular languages that the average PHP developer might be > exposed to. > > -Rasmus > --20cf30563c0bf80f6d04a9aa1d27--