Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98083 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15549 invoked from network); 31 Jan 2017 17:29:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 17:29:42 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:33046] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/D7-51557-F79C0985 for ; Tue, 31 Jan 2017 12:29:41 -0500 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6C4FB230FE for ; Tue, 31 Jan 2017 12:29:33 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Tue, 31 Jan 2017 12:29:33 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=TkgYxB/VefCUBKfd2tYbQFpLiAI=; b=piDYEJ4WF2/6YNcgBfcY lH8Xak9Q6AiOXX16FuVRJR+YBj0Cb3z+dL/W/A3aoU/SbYkGmo1muBxw9sbxfsrt qYwL5UTUcGiG/DzSsaVigwEtQeseiFvfHesQNBnWp8rjAnyihDMZBFTwLaVIxMbz Pt/6SseoPkF9E5za5l2UhLA= X-ME-Sender: X-Sasl-enc: SCZToyrwgqB/UUce3AgGYS8hfMLaV9Bl0LrOuOoVn5oP 1485883773 Received: from [192.168.42.5] (c-50-178-40-84.hsd1.il.comcast.net [50.178.40.84]) by mail.messagingengine.com (Postfix) with ESMTPA id 1F8CA245B4 for ; Tue, 31 Jan 2017 12:29:33 -0500 (EST) To: internals@lists.php.net References: <3F428CA4-8211-44E6-9B60-62ADB47934B3@koalephant.com> <642a72cd-e322-0b22-452f-dfbd521aee02@php.net> Message-ID: <37679ae0-eb90-2367-7fc0-8f0adf97a965@garfieldtech.com> Date: Tue, 31 Jan 2017 11:29:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: larry@garfieldtech.com (Larry Garfield) 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 ‘fun’ 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 tells you whether the variables inside the code are imported or not. As Stephen Reay notes: >>> After several years of JS >>> closure ‘fun’ 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 ()", 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 clutter in one line. Compare > > array_map(fn($x) => $x + 1) > > to > > array_map(function($x) => $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 RFC is to reduce the amount of typing, and therefore reading, that goes into 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 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 If there's a good reason to not use that syntax, OK, but that should be stated explicitly in the RFC with links to both HHVM and to the previous short-closure RFC. I also echo the previous call to clarify with examples how types would be used, syntactically. Since there is no "return" keyword used, that implies that no "yield" keyword can be used, either. That is, arrow-function generators are not supported. Is that correct? (In context they may not make sense to have, but that should be clarified explicitly in the RFC.) Overall I am +1 on this RFC. --Larry Garfield