Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104738 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54148 invoked from network); 15 Mar 2019 13:20:22 -0000 Received: from unknown (HELO mail-it1-f180.google.com) (209.85.166.180) by pb1.pair.com with SMTP; 15 Mar 2019 13:20:22 -0000 Received: by mail-it1-f180.google.com with SMTP id l139so9909959ita.5 for ; Fri, 15 Mar 2019 03:10:59 -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 :cc; bh=Cdu0U99kNxG5kz+2RIFgZh8JVRMiDEAUh27n7YE4n90=; b=JwIHl+QV7JEKSegc/u1gTbSOoDtr2rxI3mDi9QjqCLw+rlbVJ+dWtwHC/ocOJk7rBF a72DMP+7UpAcbTGnrAueF/jfQMzAWQOuKAWsLD25rpeedd2maU3mVl7AwVg5K+B9dgvi l4HoqSD3MuZK/E4Ux3PDDIiQjPAVcUPzk8XlAaer1pWpKXIDV99Aq8BXQZWVYklVydpZ +0Ske1ETgGWlTlgbALbFP6HrWHB21t/ENhh6sGSpEtCQQQJIR7p0pkZq06YjMLbZc144 6gkGAqayV8pqB8UqBdnmn1ZAxsOtzgQ0qx3uqQYiepVKRthor0gXDgxphrxSBOV9Plaj U0cA== 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:cc; bh=Cdu0U99kNxG5kz+2RIFgZh8JVRMiDEAUh27n7YE4n90=; b=RfbjnCZghej0+URHYAFNHfRGSrDt2X9Haw+ZdIJ29p5XVuc79aolgZ2SB2KLV2VpEp vbPHxOb89CCwIGl/LHPSOXE7timNyv4ASCHyfKXGpxUHoA2ERqsqUNRnY+L6gVynTya7 NcAt9vG9i8hyHkf8d19CguLskXiylvks4q05lVX533TcYUFeV+IqmGVoj2sY1fvgn5xo 1ozb3lzMoYHeeePZDR4Qtxm+zISt1KyEdn+4PAryK/Q0+IVLrwE4CpX1j/iR/0rD+H1X 4Kw21gfMCXSEVFLQ8xgcMirkEJWC6rNsbfsgqWQEFJHihq8CBzTnFfnYKQpD/z45TGoJ yl2Q== X-Gm-Message-State: APjAAAXgoKzi3mxiGCRR4RJg1GE/fSjyvVqJzphIh3uY1d0j9EAMnS+C +nNMYxwJrNUlAt4ezX+8ak0LwQ6RCOzu8qydbKc= X-Google-Smtp-Source: APXvYqz3YPBNkqN+oSXjDaGb5Da7WOGE5pZeo1Fr4ZLU2zAVof2tPyQDJx4JACUJ660+IqXUptiiYJVJ6l9vYQbjtjk= X-Received: by 2002:a24:7542:: with SMTP id y63mr1468113itc.70.1552644657195; Fri, 15 Mar 2019 03:10:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 15 Mar 2019 11:10:40 +0100 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000041302605841f412e" Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: nikita.ppv@gmail.com (Nikita Popov) --00000000000041302605841f412e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 15, 2019 at 10:31 AM Rowan Collins wrote: > On Fri, 15 Mar 2019 at 09:01, Alexandru P=C4=83tr=C4=83nescu > wrote: > > > My question would be: whatever syntax we are going to use that has arro= w > > syntax, let's say *$f =3D \($x) =3D> $x * 2;* are we going to also supp= ort > the > > arrow block version?: > > *$f =3D \($x) =3D> {* > > * // more operations that will have better visible on multi-line* > > > > * return $x * 2;* > > *}* > > > > > See "Future Scope" in the RFC: > > > This feature is omitted in this RFC, because the value-proposition of > this syntax is much smaller: Once you have multiple statements, the > relative overhead of the conventional closure syntax becomes small. > > We shouldn't pick a syntax that rules it out, but it can be added later, > with a separate RFC to discuss the benefits and details. > It might be worth giving some consideration to the possibility of introducing this syntax already in this RFC. The main problem with punting this off for later is that it may be necessary to refactor closures between the short and the long form regularly: You need an extra statement in the closure? You have to switch closure types, and also not forget to write our the use() list this time. On the other hand, allowing a block body for the closure does add a number of complications to this proposal: 1. Syntax choice. Given the fn() syntax, we could go for either fn() {} or fn() =3D> {}. 2. By-ref binding: While by-reference binding is not useful for single-expression closures, there will be cases where it's needed for block closures. We will also need to choose a syntax to opt-in to by-reference binding. The RFC suggests use(&), which is somewhat non-great. 3. Determining bound variables. For single-expression closures we can get away with binding all variables that are used inside the closure. Writing something like fn() $a =3D $b might cause an unnecessary binding of $a, but it's also a very contrived situation. For block closures performing assignments inside the closure will be much more common and will need some more consideration to avoid unnecessary bindings. Regards, Nikita --00000000000041302605841f412e--