Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98084 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18995 invoked from network); 31 Jan 2017 18:16:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 18:16:32 -0000 Authentication-Results: pb1.pair.com header.from=tendoaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tendoaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.182 as permitted sender) X-PHP-List-Original-Sender: tendoaki@gmail.com X-Host-Fingerprint: 209.85.217.182 mail-ua0-f182.google.com Received: from [209.85.217.182] ([209.85.217.182:32784] helo=mail-ua0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/58-51557-F74D0985 for ; Tue, 31 Jan 2017 13:16:31 -0500 Received: by mail-ua0-f182.google.com with SMTP id i68so278496841uad.0 for ; Tue, 31 Jan 2017 10:16:31 -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:to; bh=thHB6SlCBNXQ2dB9PY5pLKQf8xe/H6dZVDtXC4hpxrY=; b=eY+EOas2z7Fql+aHuv2l/dh6wtTv9hvvIb5WgcuWkdegBhkHLHqb9VJ6i4GJVGJH37 YfxHmjLpFFCBoJ42cZzgDkOKuUMh6V8iyU5E13NGrK+WqCHwxGOkJsncnRsWscNykYLL mHI6gjCnOk/QXq5pa3MP1UasuZqRxatCp/ADtmVHf76okf3D34myawdlZNP4RBE4jNyO Qwrux4j4cMTZ0VU1ecEWXdIGz1Yt0QXYJBAU3wafbw9967//i+nGFw9k1am5FP6n7sKU MJZ12pnEZ57H6QlIRJlfDoCJ8B++GTPFkEBnnPIsBj9eYfVLFBeD7Cgud78qG6zx7Lk7 JpRA== 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:to; bh=thHB6SlCBNXQ2dB9PY5pLKQf8xe/H6dZVDtXC4hpxrY=; b=q///xlm+GR5WP91X7huRQmFTvrJCdTKD/YTnI/nITdEGMLGCXllTLUp4S9NHCwlj6m Fri2ZtVDtLzs56k8Bm7on9V6l+lb0A2FWkeWXNPD/JBLITNqirM9z96xVUOvmK1D4d6z AYlub/K9Sj3wC5AYM1UBAfpsBt18S0QERT+uYZ9k+w3hIuosGtNTLkSqvrDn019bZRJt B+PFawNKXLcWLUV9hcZNLv6q4dfHgeQxgeNe1t0C2z28qSvZ9lrAZwOdaKz2EDFK0bau yTYmT9nfNY6jxaS6smZVzTWU73y0gtJ8x3jOBIme34s7xftraqBwbdFu7+DR8Z2zNxgH e0wQ== X-Gm-Message-State: AIkVDXKEO7QPKi13nyfHPvo0YgnkiktXHIfCxHEF7Q9q7sLZK7sa1ndGk0zYTUbyprM2073e+GlhO3aXfbqKXA== X-Received: by 10.159.38.229 with SMTP id 92mr14942413uay.102.1485886588181; Tue, 31 Jan 2017 10:16:28 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.35.15 with HTTP; Tue, 31 Jan 2017 10:16:27 -0800 (PST) In-Reply-To: <37679ae0-eb90-2367-7fc0-8f0adf97a965@garfieldtech.com> 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 13:16:27 -0500 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=94eb2c047d4a43e77f054767ee67 Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: tendoaki@gmail.com (Michael Morris) --94eb2c047d4a43e77f054767ee67 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 in= herit 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 tells >> you whether the variables inside the code are imported or not. As Stephe= n >> Reay notes: >> >>> After several years of JS >>>> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only in= herit 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 ()", as >> 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 clutte= r >> 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 whole >> 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 RF= C > is to reduce the amount of typing, and therefore reading, that goes into > using simple closures as first-class values. Using longer keywords inste= ad > of shorter ones is counter to that aim. It sounds like the earlier > proposal of keyword-less closures isn't technically feasible or it would > 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. --94eb2c047d4a43e77f054767ee67--