Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104718 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65793 invoked from network); 14 Mar 2019 18:51:25 -0000 Received: from unknown (HELO mail-it1-f171.google.com) (209.85.166.171) by pb1.pair.com with SMTP; 14 Mar 2019 18:51:25 -0000 Received: by mail-it1-f171.google.com with SMTP id o76so2236391ita.3 for ; Thu, 14 Mar 2019 08:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=v+l80C3t6NltqRgQjacSW49Vx3bLRu8C2+fmzR+x1go=; b=j1U3ZXq/rCXm6miSsUEgGeOQwA/T83FAzCJe+3xEclEqYHzfPkAil0WKaGa3e6ZJU4 x7ifUieyq+bcDw0z4x4pTYcRosk4BDyUEqUKSVV39SxcP1VeqKS/xsiY/vM2zIu/bJrd Z2S2XfgDhJNuPBvZtczKDs+HR/Sg9nkoeByS+QSdbm9RpdkGjadgASy1Dmd++v549/er WCDPEFknFGzxSnFmY5azZKkEF3elSeiO/xLs9hR1idOu7fBakfyJD5SzfWPbIgHOG5Dy csk0YnZAq7hKR+mk+s+hJVdO2NIpDyKzBmUWWRJawrX9vyFdSgNUDiZzx/oDwfT50h0R fFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=v+l80C3t6NltqRgQjacSW49Vx3bLRu8C2+fmzR+x1go=; b=NQcYSKN1LPQeqJunMTl5mm5lItxr+Vit2y22EIasH7aPKD2uMZVaeYaJ27shwDwlLS lhenqNyNLmaNbPal2Tqo62p1EaosBpbV6E61/a7kiDMXHDGDclXlCdvahxC0yBBLtZxC VOFC6N0UUSh11DuT0QOQ+HH0TYmYiWYFHbP9Gu2tbOBmNHAxtPj+17XbJMyzy6Mz0q4N /NwH/sJN+Pmb0+ee2AWlF6pxXch0ev61KTLILSCAUzA7bjaejRswS9bhHfy5wNrXcoIJ S6W33WON3s3BJ2LYpfDnPEn2dwrvSGaPzbiSc85hjAXX8wZbccQaV9Imo1NvixUps5Nn 1ebA== X-Gm-Message-State: APjAAAWX36vOoM6LYfV5MftGE/sc9G0DDPHVnh1Tds3OnOWUjhEDpFxb UMVhLF9qDeFrtOVUUSPecmpOvib3BMxS8+ap1jFjBgnQ X-Google-Smtp-Source: APXvYqzT1hFZKCp1mDX5w0+s+FYNa0s6PRgQ7YGvz1i6RBg1HOlCfTD41zolTj8PREn3OJWMSFtRtHKR4KzbHVkpdd8= X-Received: by 2002:a24:7542:: with SMTP id y63mr2443864itc.70.1552578110118; Thu, 14 Mar 2019 08:41:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 14 Mar 2019 16:41:33 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000bd62dc05840fc210" Subject: Re: [RFC] Arrow functions / short closures From: nikita.ppv@gmail.com (Nikita Popov) --000000000000bd62dc05840fc210 Content-Type: text/plain; charset="UTF-8" On Wed, Mar 13, 2019 at 4:56 PM Nikita Popov wrote: > Hi internals, > > Motivated by the recent list comprehensions RFC, I think it's time we took > another look at short closures: > > https://wiki.php.net/rfc/arrow_functions_v2 > > This is based on a previous (withdrawn) proposal by Levi & Bob. It uses > the syntax > > fn($x) => $x * $multiplier > > and implicit by-value variable binding. This example is roughly equivalent > to: > > function($x) use($multiplier) { return $x * $multiplier; } > > The RFC contains a detailed discussion of syntax choices and binding modes. > > Regards, > Nikita > As a small update, I've implemented a proof of concept that uses the ($x) ==> $x * $multiplier syntax (or $x ==> $x * $multiplier for short) in https://github.com/php/php-src/pull/3945. As mentioned in the RFC, this requires scanahead in the lexer. This syntax is in principle still on the table, though personally I prefer fn($x, $y) => $x * $y over ($x, $y) ==> $x * $y. The main redeeming quality of ==> is that it supports the paren-less variant $x ==> $x. Taking into account the lexer hackery it requires (and which will also be required in any 3rd party tooling), this would not be my preferred choice. Regards, Nikita --000000000000bd62dc05840fc210--