Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88041 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71051 invoked from network); 3 Sep 2015 23:42:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Sep 2015 23:42:16 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:33956] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AA/91-60419-7DAD8E55 for ; Thu, 03 Sep 2015 19:42:15 -0400 Received: by laeb10 with SMTP id b10so3140621lae.1 for ; Thu, 03 Sep 2015 16:42:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=ETRE9sC+zo6NE8/BCYzmNJ1w52rYZG2YHCk5MAD7GBM=; b=Tsx1ar+sB2cS2JZ0uC3yMJFzM0SL4i79Cd1KNbCH4qvSLpEvrATGX4RYOnaH75RuH2 mev/HVHl4HI0jlAZSkNZxXaV9StypjLR5AOykbKtoaB1Q6IyW9Qx9IRWBAYcAvRZInqf 2xUQLj1lNaQYTt8mt5LCL6YpheOLIgaFkDP0Z3RJk1vpqRa0W72HR4bNGkFvTqPhoQ92 yxq5BmUBfib1BYhVyi8HUeH48z/WQiJfgL9GGfcen23hjbv0IIWcraizNuSqMgGlAaWc I5YhQ36dId02z70MCIe1A8dEvJTJWHqNrm55iNebUB0Jod6LV8WhiOZQl/8gqvOMyp5x ALyQ== X-Gm-Message-State: ALoCoQm/m17ycLIiWyaJeqXFa5ayeh2od286eHZp2mZ5MgFsTr33ftUOc0lTilT/w2hBDQL6Z5We MIME-Version: 1.0 X-Received: by 10.112.218.5 with SMTP id pc5mr533757lbc.97.1441323731924; Thu, 03 Sep 2015 16:42:11 -0700 (PDT) Sender: php@golemon.com Received: by 10.112.34.102 with HTTP; Thu, 3 Sep 2015 16:42:11 -0700 (PDT) X-Originating-IP: [2620:10d:c090:200::6:11d] In-Reply-To: <55E77CA9.7050609@gmail.com> References: <55E77CA9.7050609@gmail.com> Date: Thu, 3 Sep 2015 16:42:11 -0700 X-Google-Sender-Auth: qvtaVsDIM2-PXFdSVJlsyNt5m8Y Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: pollita@php.net (Sara Golemon) On Wed, Sep 2, 2015 at 3:48 PM, Rowan Collins wrote: > Amendment 1. Only allow the single-expression form of the short syntax; full > function bodies must be declared with the existing function(){ ... } syntax. > This gives a clearer distinction between how the two syntaxes can be used. > I'm down with that. Short syntax works best when it's concise. If my callback needs to do more, I tend to prefer writing the method elsewhere, and naming the variable its in according to what it does. Yay readability! > Amendment 2. Make the ~> operator non-associative, so that lambdas returning > lambdas would need an extra pair of brackets making the nesting explicit. To > take one of Anthony's examples: > > function partial(callable $cb) { > return $left ~> ( $right ~> $cb($left, $right) ); > } > > It's now at least clearer that there are two different anonymous functions > here, even if it's not entirely clear what they're trying to achieve... > Again, I support this. I use parenthesis generously so that there's never a doubt. And because we got ternary's associativity wrong. > Amendment 3. Make the parentheses around the argument list mandatory so that > (if Amendment 1 is also adopted) there is only a single variant of the > syntax, namely "( param list ) ~> expression". > I like it for consistency, but I will say that 80% of my short lambda uses are callbacks for map and filter, which are single arg callbacks (when used without keys), so I do seldom see parens used at all.... in fact, I think that just convinced me why we need to be consistent. Imagine someone not understanding why adding a second parameter breaks their short lamba declaration... > Amendment 4. Consider a syntax involving an explicit "use". This one > requires a bit more exploration, but maybe something like: > ( $a use $b ) ~> $a + $b > or: > ( $a ) use ( $b ) ~> $a + $b > Not a fan of this one at all. Maybe it's my Javascript showing through, but I like the automatic capture. Not that I'd cry foul if it were required though. Good short lambdas are short short lambdas, so their use statements would be small anyway. -Sara