Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98087 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23814 invoked from network); 31 Jan 2017 18:37:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 18:37:20 -0000 Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.169 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.217.169 mail-ua0-f169.google.com Received: from [209.85.217.169] ([209.85.217.169:32981] helo=mail-ua0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/59-51557-F59D0985 for ; Tue, 31 Jan 2017 13:37:20 -0500 Received: by mail-ua0-f169.google.com with SMTP id i68so278919138uad.0 for ; Tue, 31 Jan 2017 10:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=/Qefzw6vJWAq6gbJilZuGh2JIAx5FDM9TcKnIMGltMo=; b=I2+AFqXx5GfXOfLXGo5HttWlgh6EhsyLtIIRDnzCFgKuZekG0nKLxGgMZfy6wNSb+A 1xIOKT6rnNeLVmyhk2L4k7IDfZ3Xz0ePi50OORz/qr47nuwOKV9OJOvmqyjnzUx/y+Ss 5t+96E9Zv8qFZ4J+i6oMmDU5xOwvB7kFnAUm+r9eIpZRw3YP8D3h3z2tJ5JbzSu4LcPC NSoL7p7/rvNAp2A2Uyi8AMC7Ke8HarxLENNUqFQWCn9cmxqpWE7rEUSj27YXVdyNK46E 9bFBqhT1ZalQTdj3gmxj27ZGuILaccsYY8PWst5KIJp6nEBCrpJbwMeKmCqcNGMBjxGz WJ9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=/Qefzw6vJWAq6gbJilZuGh2JIAx5FDM9TcKnIMGltMo=; b=UjQTtbHbZNSSMeVTeWQZKD8vQfN29CFj8uecmnwFAcs6U9v6+S6CVNJTbIm4EeEpyJ v5QKd+5ZE5fSHkqMk0QtpVXbpXvnvCdUywkq2RHTKSVpl2BI7wXTx14jZhcVYl2cXTDR hWpCSq0++hrhIM1wO1S2+R7peJTUXs23AyBY7WXVWuE0BB5tYAPCrh9+ws/KrsljmMo9 saR/nOmbXR/sw9tLfl0J8J1WsSBn4lPw4HGkkcO4WpwwGquyM3Fuh2D++MqAGANHMPAU ZubJTT1RF7Wt51HpmsvhDyYOVMQzfh1SAyqg2IVpIoFt9RKM93JNRsc3CY5G9Tp7t0T0 RxiA== X-Gm-Message-State: AIkVDXLWAFrPMuVLBej6tvLTtjMbJqg7f7vZaCXhdjTdyeMq1MoiAnwQD2MXOOhB5ez5k4TdVEwZHiOZkbDlOQ== X-Received: by 10.176.74.207 with SMTP id t15mr15004780uae.169.1485887836559; Tue, 31 Jan 2017 10:37:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.29.133 with HTTP; Tue, 31 Jan 2017 10:36:55 -0800 (PST) In-Reply-To: References: <3F428CA4-8211-44E6-9B60-62ADB47934B3@koalephant.com> <642a72cd-e322-0b22-452f-dfbd521aee02@php.net> <37679ae0-eb90-2367-7fc0-8f0adf97a965@garfieldtech.com> Date: Tue, 31 Jan 2017 16:36:55 -0200 Message-ID: Cc: PHP internals Content-Type: multipart/alternative; boundary=f403045f8efcac9e2e05476838d3 Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: david.proweb@gmail.com (David Rodrigues) --f403045f8efcac9e2e05476838d3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I guess that should avoid the usage of fn() or function() before arguments (or then make it optional, but I don't like to give much options). Some possibilites: array_map(($x) return $x + 1); // or array_map(($x) =3D $x + 1); // or array_map(($x) =3D> $x + 1); // or array_map(($x) { $x + 1 }); Then: array_map(($x) use ($y) { $x + $y }); array_map(($x) { $x + $y }); =E2=80=8B// maybe use($y) is needless here array_map(($x) { $x + $this->y }); Or if arguments could be omitted: array_map({ $0 + 1 }); 2017-01-31 16:16 GMT-02:00 Michael Morris : > On Tue, Jan 31, 2017 at 12:29 PM, Larry Garfield > wrote: > > > On 01/31/2017 05:14 AM, Bob Weinand wrote: > > > >> > >>> In the case that regular closures got auto-capture, would a > >>>> `use($foo, $bar, $baz)` segment on a closure still be honoured (i.e. > >>>> disable auto-capture), and would it have any impact (positive or > >>>> negative) on performance/memory usage? After several years of JS > >>>> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only = inherit the > >>>> variables you explicitly `use()` in closures. > >>>> > >>> Wouldn't there be just too many existing closures, which do not use > >>> `use` but (maybe) expect a clean scope? > >>> > >> > >> The RFC is exclusively proposing single-expression short Closures. > >> We do NOT want multi-statement short Closures; it is a *feature* that > >> generic Closures need an "use ($foo, $bar)". > >> This vastly improves readability and debuggability - it basically tell= s > >> you whether the variables inside the code are imported or not. As > Stephen > >> Reay notes: > >> > >>> After several years of JS > >>>> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only = inherit the > >>>> variables you explicitly `use()` in closures. > >>>> > >>> > >> So, auto-import for generic Closures definitely isn't an option. > >> Just on short, single-line Closures there is no benefit to "use ()", a= s > >> EVERY variable used in the short Closure is supposed to be an imported > >> variable. There is no point in forcing the user to distinguish between > >> imported and local variable here. > >> > >> Also, using "fn" in favor of "function" has the advantage of less > clutter > >> in one line. Compare > >> > >> array_map(fn($x) =3D> $x + 1) > >> > >> to > >> > >> array_map(function($x) =3D> $x + 1) > >> > >> The syntactical construction is already pretty clearly showing what's > >> going on. The "function" keyword itself is already larger than the who= le > >> body. It distracts while reading the actual code. > >> Additionally, using "fn" is optically highlighting the fact that it's = a > >> short-Closure with auto-import and not a normal Closure with explicit > >> import. > >> > >> Thanks, > >> Bob > >> > > > > I must agree with Bob and the other authors. The entire point of this > RFC > > is to reduce the amount of typing, and therefore reading, that goes int= o > > using simple closures as first-class values. Using longer keywords > instead > > of shorter ones is counter to that aim. It sounds like the earlier > > proposal of keyword-less closures isn't technically feasible or it woul= d > > make sense to argue for that. > > > > My question is why there's no mention of HHVM short closures, or the > > previous RFC to take that approach. See: > > > > https://docs.hhvm.com/hack/lambdas/introduction > > > > > > > > For what it's worth I'd rather look at > > array_map( $x =3D=3D> $x + 1); > > than > > array_map( fn($x) =3D> $x + 1 ) > > Not to mention the former isn't a bc break. > --=20 David Rodrigues --f403045f8efcac9e2e05476838d3--