Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53673 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56392 invoked from network); 29 Jun 2011 17:34:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2011 17:34:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.170 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 74.125.83.170 mail-pv0-f170.google.com Received: from [74.125.83.170] ([74.125.83.170:48028] helo=mail-pv0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/B5-25278-2326B0E4 for ; Wed, 29 Jun 2011 13:34:42 -0400 Received: by pvh10 with SMTP id 10so1023272pvh.29 for ; Wed, 29 Jun 2011 10:34: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:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=EDmLOOYPQQ00Pv+IVj1giWZFoF/4s2ZIpYFVZaohIIE=; b=TlSbyCtjAu5FFmAXqOv7DjJo/I8Sk9qGlOhdopD5QaPJbo+PZ4Vpd0q//EeLzqzZaU CSGB0zVcu4cDUtWCBEXOLFn0zFJU5xI1f9Efa4Os5GAnag13049gpo6R9rUK7NkDFqQl qLlRTb4dinCjVwTCBXwqwxvw0YtI0PutC7Pnc= MIME-Version: 1.0 Received: by 10.68.56.33 with SMTP id x1mr1401911pbp.516.1309368879655; Wed, 29 Jun 2011 10:34:39 -0700 (PDT) Received: by 10.68.56.104 with HTTP; Wed, 29 Jun 2011 10:34:39 -0700 (PDT) In-Reply-To: References: <1ACBA7A9-A78C-4D7C-8B76-F87EDE13381E@squarecrow.com> Date: Wed, 29 Jun 2011 13:34:39 -0400 Message-ID: To: John Crenshaw Cc: Jarrod Nettles , "internals@lists.php.net" , "neufeind@php.net" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Inline Lambda Functions From: ircmaxell@gmail.com (Anthony Ferrara) Well, we could take python's approach and use a syntax similar to this: array_filter($source, lambda $x: $x < 5); array_map($source, lambda $x, $y: $x < $y); However, I would question the need. Pythonic lambdas cannot contain anything but expressions. Therefore they cannot have any meaningful side effects. While this is good, it also raises the question as to the need for it. PHP has first-class anonymous functions, something which python does not (it has local functions, or lambdas, but no true anonymous function, every non-lambda has a name). So the need in PHP for a lambda style construct is greater than PHP's. And what's the gain for PHP? A few less characters to type? I'm not sure that readability is gained, compare: array_filter($array, function($element) { return $element < 5; }); and array_filter($array, lambda $element: $element < 5); I feel the first is more readable at a glance. Anthony On Wed, Jun 29, 2011 at 1:03 PM, John Crenshaw w= rote: > >> Instead of this..... >> >> array_filter($source, function($x){ return $x < 5; }); >> >> Being able to do this..... (or something like it). >> >> array_filter($source, $x =3D> $x < 5); > > This really isn't clear. Deciphering the intent of the code requires look= ing at all the surrounding stuff, because it could mean something totally d= ifferent in an array. In other words, > > =A0 =A0// This would be a lambda > =A0 =A0array_filter($source, $x =3D> $x < 5); > =A0 =A0// This would not > =A0 =A0array($source, $x =3D> $x < 5); > =A0 =A0// and this would not > =A0 =A0call_user_func_array('array_filter', array($source, $x =3D> $x < 5= )); > > The fact that the syntax for an expression isn't portable in places where= (so far) every other expression has been, is a serious concern. > > Additionally, the proposed syntax is unusable for functions with more tha= n one line, making it similar in badness to if statements without braces. I= MO the current syntax for inline functions is perfectly sufficient, even fo= r the PLINQ example given earlier, and has massive advantages over this one= in terms of readability, affordance, flexibility, and language clarity. > > John Crenshaw > Priacta, Inc. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >