Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104705 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 69098 invoked from network); 14 Mar 2019 05:39:58 -0000 Received: from unknown (HELO out2-smtp.messagingengine.com) (66.111.4.26) by pb1.pair.com with SMTP; 14 Mar 2019 05:39:58 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id EDB3E24715 for ; Wed, 13 Mar 2019 22:30:14 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 13 Mar 2019 22:30:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:references:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=LG+5d9Lbu7nSfe5Pw H0nXeTnBiISQ3scv9q6wNux72A=; b=5LCY5k7B6qI6ITq0zuId/Rb+SlVVKLKi3 8X15+8FF2JJbpmULwEEOAa+pxwB9Dhg+HgYPu1x0mxIESJnOcMEy9aaSQrGfVPxQ O73lOo+tyFnjdTVJfi5U9ubpWVhtGYSMgfBv+UIyTetbqVH77qOwJy1nDtcQEEUt sZYM700hXWNRvSd7kgCIYZD0vCZ4f6aa02W+zGTPTc5uekqMy3RBYC8jPaF4Fek2 EfSddfeg/IZ1Y5uyCNkFDQBuug+CMFrnymWi/jGyxqgdireNpPgM8PNuwcBwT0vR 8hlAj2/bOpySvgk84xeEP4sUq3kTxuQE8tAVRw+W/HSYd+1nKIWsA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrhedugdegjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfkfgjfhffhffvufgtsehttdertd erredtnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehg rghrfhhivghlughtvggthhdrtghomheqnecuffhomhgrihhnpehphhhprdhnvghtnecurf grrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtgho mhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4DBEDB46AA; Wed, 13 Mar 2019 22:30:14 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.5-925-g644bf8c-fmstable-20190228v5 X-Me-Personality: 10727885 Message-ID: In-Reply-To: References: Date: Wed, 13 Mar 2019 22:29:58 -0400 To: internals@lists.php.net Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 13, 2019, at 11:57 AM, 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 A very thorough writeup, thanks, Nikita! +1 from me. Two questions: The section on static arrow functions implies, but doesn't say outright, that $this will auto-bind just like any other variable if used inside an arrow function. Is that the case? If so, that should be made explicit for clarity. With regards to comprehensions, this RFC says that arrow functions have a single, implicitly returned statement. How would that play with a function body that includes a yield? Would that work "as expected" (the arrow function becomes a generator function that can be iterated, making it functionally a comprehension) or would it fail in some mysterious way? --Larry Garfield