Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-04-17 Thread Wes
I like it. Only exception is: ``` fn&() => ...; ``` Which I would prefer to see reserved for the purpose that you've written as: ``` fn() use(&) => ...; ``` The & symbol of "return by ref", should be placed on the right of the parentheses, near the return type: ``` fn(int &$x)&: int => $x; fn(

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-15 Thread Rowan Collins
On Fri, 15 Mar 2019 at 10:10, Nikita Popov wrote: > 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

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-15 Thread Nikita Popov
On Fri, Mar 15, 2019 at 10:31 AM Rowan Collins wrote: > On Fri, 15 Mar 2019 at 09:01, Alexandru Pătrănescu > wrote: > > > My question would be: whatever syntax we are going to use that has arrow > > syntax, let's say *$f = \($x) => $x * 2;* are we going to also support > the > > arrow block vers

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-15 Thread Nikita Popov
On Thu, Mar 14, 2019 at 3:04 PM Mathieu Rochette wrote: > > Hi, > > it's nice to see this going on again :) > > while reading the rfc I was wondering, why do we need the "static" > keyword, couldn't static function be detected automatically ? > I've added a note regarding this in https://wiki.ph

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-15 Thread Rowan Collins
On Fri, 15 Mar 2019 at 09:01, Alexandru Pătrănescu wrote: > My question would be: whatever syntax we are going to use that has arrow > syntax, let's say *$f = \($x) => $x * 2;* are we going to also support the > arrow block version?: > *$f = \($x) => {* > *// more operations that will have be

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-15 Thread Alexandru Pătrănescu
Hi, To start with, I personally understand why a prefix character is needed before parenthesis to make the parser simpler. I would like another simpler option but will have to investigate more on this. My question would be: whatever syntax we are going to use that has arrow syntax, let's say *$f

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread G. P. B.
On Thu, 14 Mar 2019 at 18:20, Josh Di Fabio wrote: > On Thu, Mar 14, 2019 at 3:49 PM Rowan Collins > wrote: > > > > Is it really that important to save two key strokes per closure? > > > > I'd say that the (probably overwhelming) majority of arrow functions > have a single parameter and, in thos

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Josh Di Fabio
On Thu, Mar 14, 2019 at 3:49 PM Rowan Collins wrote: > > Is it really that important to save two key strokes per closure? > I'd say that the (probably overwhelming) majority of arrow functions have a single parameter and, in those cases, the JS syntax saves four characters, ignoring whitespace. A

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Rowan Collins
On Thu, 14 Mar 2019 at 15:10, Benjamin Morel wrote: > The problem, as I understand it, is not avoiding ambiguity, it's avoiding >> lookahead. > > > You're right, I was only thinking about resolving the ambiguity with array > keys. It's too bad if the parser implementation considerations take > pr

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread David Rodrigues
Em qui, 14 de mar de 2019 às 03:17, Rowan Collins escreveu: > I don't think this helps, because you can put brackets around any > expression, for precedence, and any expression can appear on the left of an > array literal: > > $foo = [ ($bar + 1) * 2 => $baz ]; > > So the following, while redunda

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Benjamin Morel
> > The problem, as I understand it, is not avoiding ambiguity, it's avoiding > lookahead. You're right, I was only thinking about resolving the ambiguity with array keys. It's too bad if the parser implementation considerations take precedence over the purity of the language, but I can understan

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Rowan Collins
On Thu, 14 Mar 2019 at 14:12, Benjamin Morel wrote: > This makes me thinking, has this syntax been considered? > > ($x) => { $x * $y } > > Nested: > > ($x) => { ($y) => { $x * $y } } > Wouldn't this have all the same parser problems as the RFC discusses? The problem, as I understand it, is not

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Benjamin Morel
This makes me thinking, has this syntax been considered? ($x) => { $x * $y } Nested: ($x) => { ($y) => { $x * $y } } AFAICS, we don't need the brackets around the whole expression, as this should be parsable without any ambiguity; and the syntax would be closer to that of JavaScript. On Thu,

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Mathieu Rochette
Hi, it's nice to see this going on again :) while reading the rfc I was wondering, why do we need the "static" keyword, couldn't static function be detected automatically ? I guess this apply to the existing closure syntax as well so to get more on this topic I'll share my preferences on th

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-14 Thread Rowan Collins
On 13 March 2019 15:56:40 GMT+00:00, Nikita Popov wrote: >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 Hi Nikita, Thanks for reviving this. I think the RFC does a great job of justifyin

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Rowan Collins
On 14 March 2019 04:01:54 GMT+00:00, David Rodrigues wrote: >1. Your example with "($x) => $x" consider the use of "$x => $x", but >not >specifically "($x) => $x". I mean: maybe it can accept "($x) => $x" but >not >"$x => $x" because of the array conflict (as mentioned), and with that >we >avoid

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread David Rodrigues
I have two doubts about the RFC: 1. Your example with "($x) => $x" consider the use of "$x => $x", but not specifically "($x) => $x". I mean: maybe it can accept "($x) => $x" but not "$x => $x" because of the array conflict (as mentioned), and with that we avoid to create a new keyword "fn". So pa

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread 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 & B

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Björn Larsson
Den 2019-03-13 kl. 16:56, skrev Nikita Popov: 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

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Ben Ramsey
> On Mar 13, 2019, at 15:56, Rowan Collins wrote: > > I suggest you both read the RFC; about half the page is dedicated to > summarising the syntaxes which have been considered, and the pros and cons of > each. > > The summary of that syntax begins: > > > This is both the most popular and the

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Rowan Collins
On 13/03/2019 20:37, Chase Peeler wrote: Anyone considered? ($x) => $x * $multiplier I use this format a lot in javascript, so I like not having any indicator. I can't remember which language it was, but they didn't even require the parentheses if there was only a single input: $x => $x * $mult

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Chase Peeler
On Wed, Mar 13, 2019 at 4:26 PM Travis van der Font wrote: > Arrow functions are ternary operators to functions. > While they are nice and shorten, they can be hard to read at times; > considerably to people who aren't used to them which is surprisedly a > majority of PHP programmers. > > Having

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Travis van der Font
Arrow functions are ternary operators to functions. While they are nice and shorten, they can be hard to read at times; considerably to people who aren't used to them which is surprisedly a majority of PHP programmers. Having them optional sure, but not necessary. Feel free to decide between fn()

Re: [PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Ben Ramsey
> On Mar 13, 2019, at 10:56, 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

[PHP-DEV] [RFC] Arrow functions / short closures

2019-03-13 Thread Nikita Popov
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

Re: [PHP-DEV] [RFC] Arrow Functions

2015-10-15 Thread Björn Larsson
Den 2015-10-03 kl. 01:17, skrev Levi Morrison: I messaged the list about this feature before I had the RFC written up for it. The RFC[1] is slightly different from what I proposed in the previous thread, so please read the RFC to make sure you understand what is being proposed before replying her

Re: [PHP-DEV] [RFC] Arrow Functions

2015-10-03 Thread Thomas Bley
Pavel Kouřil wrote on 03.10.2015 10:06: > On Sat, Oct 3, 2015 at 1:17 AM, Levi Morrison wrote: >> I messaged the list about this feature before I had the RFC written up >> for it. The RFC[1] is slightly different from what I proposed in the >> previous thread, so please read the RFC to make sure

Re: [PHP-DEV] [RFC] Arrow Functions

2015-10-03 Thread Pavel Kouřil
On Sat, Oct 3, 2015 at 1:17 AM, Levi Morrison wrote: > I messaged the list about this feature before I had the RFC written up > for it. The RFC[1] is slightly different from what I proposed in the > previous thread, so please read the RFC to make sure you understand > what is being proposed before

[PHP-DEV] [RFC] Arrow Functions

2015-10-02 Thread Levi Morrison
I messaged the list about this feature before I had the RFC written up for it. The RFC[1] is slightly different from what I proposed in the previous thread, so please read the RFC to make sure you understand what is being proposed before replying here. Here's a small example: $y = 10; $re