Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Kosit Supanyo
Hi Mike I think your hypothetical PHP syntax won't happen. Not because it's bad idea but because PHP just simply can't. I understand that you came up with that idea from Golang background but the reason Golang can do that because in Golang, assignments are statement not expression. Even `++` or

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Rowan Tommins
On 21/10/2019 21:18, Mike Schinkel wrote: But to follow up to clarify what I was thinking consider the following/ (hypothetical) /PHP syntax. Note that the return value has two comma separated values, and the assignment can accept those multiple values into two comma separated

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
> On Oct 20, 2019, at 11:11 PM, Kosit Supanyo wrote: > Ok, so let's look at a scenario. Will we be able to do this in the future, if > we decide to allow multiple expressions to result in a final value? > $y = switch ($x) { > case 1 => $arr = get_array(), array_pop($arr), > case -1 =>

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
> On Oct 21, 2019, at 4:51 AM, Rowan Tommins wrote: > > On Sun, 20 Oct 2019 at 22:35, Mike Schinkel wrote: >> I would much prefer to use a switch for multiple, mutually exclusive cases >> no matter what how complex the expression is because with a switch the >> cases expressions line up

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
> On Oct 21, 2019, at 11:12 AM, Rowan Tommins wrote: >> What if in the future PHP implements variadic syntax for assigning to >> arrays, e.g. $var = 1,2,3 where $var could satisfy a $variadic parameter >> set of parameters w/o requiring `...`? If PHP embraces that — note GoLang >> has something

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Rowan Tommins
On Mon, 21 Oct 2019 at 15:13, Mike Schinkel wrote: > Ok, so let's look at a scenario. Will we be able to do this in the future, > if we decide to allow multiple expressions to result in a final value? > $y = switch ($x) { >case 1 => $arr = get_array(), array_pop($arr), >case -1 => $arr

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
> On Oct 20, 2019, at 7:59 AM, Rowan Tommins wrote: > On 19/10/2019 17:40, Kosit Supanyo wrote: >> Like function declaration and function expression in JavaScript, if >> `switch` appears as first token at statement level it will be recognized as >> statement but if `switch` is in expression

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Kosit Supanyo
Hi Rowan I'm not sure is the right syntax for type guards, but it's possible > we'd want a different syntax for new switch/match functionality anyway. I've decided to change the syntax to `(: foo)`. It may look weird at frist but it is able explain why I think this syntax is more appropriate.

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Rowan Tommins
On Sun, 20 Oct 2019 at 22:35, Mike Schinkel wrote: > What restriction are you referring to? The forced `default` or the > semi-colon being required? > > Neither; I was referring to not being able to put a switch expression as a statement on its own, which Kosit has explained is a limitation of

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Kosit Supanyo
Hi Mike > Ok, so let's look at a scenario. Will we be able to do this in the future, > if we decide to allow multiple expressions to result in a final value? > $y = switch ($x) { > case 1 => $arr = get_array(), array_pop($arr), > case -1 => $arr = get_array(), array_unshift($arr), >

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Kosit Supanyo
Hi Mike In a brace-enclosed block statements are separated by semi-colons, not > commas. Yes because they are statements, that's the point which I've stated many times. And if your argument is that there's no place in PHP that uses commas within curly braces, you're wrong. PHP already has one.

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
> On Oct 20, 2019, at 7:08 PM, Kosit Supanyo wrote: > > Yes because they are statements, that's the point which I've stated many > times. And I am suggesting that a block-enclose expression should not be limited to expressions only, but instead be able to use statements in the future. Using

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Rowan Tommins
Hi Kosit, On Sun, 20 Oct 2019 at 16:20, Kosit Supanyo wrote: > You can recognize the difference of those by looking for `=>` right? But > the parser generator (bison) cannot do that in LR mode (it maybe can in GLR > mode but I'm sure that would be unacceptable due to performance losses/more >

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Mike Schinkel
Hi Kosit, Thank you for your reply. > On Oct 20, 2019, at 3:54 AM, Kosit Supanyo wrote: > > Hi Mike > > Is there a strong reason to change to using fat arrows and colons? > > The reason is statement/expression semantic. Okay, so you chose commas and fat arrows because of perceived

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-21 Thread Kosit Supanyo
Hi Rowan Thank you for your reply. Was this restriction added to make the implementation easier, or because > you thought it was a useful feature? > This is not a restriction but a result of implementation workarounds. Let's see: switch ($x) { case 1: echo "ONE\n"; break;

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-20 Thread Rowan Tommins
Hi Kosit, There's some really interesting ideas in here, thanks for sharing them. On 19/10/2019 17:40, Kosit Supanyo wrote: Like function declaration and function expression in JavaScript, if `switch` appears as first token at statement level it will be recognized as statement but if `switch`

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-20 Thread Kosit Supanyo
Hi Mike Is there a strong reason to change to using fat arrows and colons? The reason is statement/expression semantic. The reason for choosing comma over semicolon is because in PHP semicolons are used only as statement separator while commas are used as expression separator within brackets

Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-19 Thread Mike Schinkel
> On Oct 19, 2019, at 12:40 PM, Kosit Supanyo wrote: > > Hi Internals > > I've just finished an implementation of 'switch-expression' that have been > discussed recently. So I would like to present my ideas here. This is great to see that you proactively implemented this. > The basic syntax

[PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo

2019-10-19 Thread Kosit Supanyo
Hi Internals I've just finished an implementation of 'switch-expression' that have been discussed recently. So I would like to present my ideas here. The basic syntax of switch-expression in this implementation is: $result = switch ($expr) { case $cond1 => $result1, case $cond2 =>