(This time to the list)

> On 18 Mar 2017, at 10:19, ToddAndMargo <toddandma...@zoho.com> wrote:
> Request for Enhancement:
> 
> Would you consider throwing a compiler error on the following:
> 
> perl6 -e 'my $x=2;my $y=3; if $x = $y {say "yes";} else {say "no";}’
> yes

FWIW, I don’t think that will ever become a compile time error, but a warning 
may be in place.  Even although in Perl *5* this has been discussed at length 
and considered to be a feature rather than a bug or a trap.


> It should have two == signs if it is followed by a {do something}
> 
> This is the correct way:
> 
> $ perl6 -e 'my $x=2;my $y=3; if $x == $y {say "yes";} else {say "no";}'

In Perl 5 many people use the syntax to assign the value of a complicated 
expression to be useable inside the if statement:

 if (my $x = frobnicate(42)) {
     say $x
 }

In Perl 6, we have a different syntax for that, by using a pointy block:

 if frobnicate(42) -> $x {
     say $x
 }

Generally, in Perl 5 and Perl 6, when comparing against a constant, you could 
consider teaching yourself to always put the constant on the left-hand side:

 if 42 == $x

Should you then make a mistake, it will at least be obvious at runtime:

 $ 6 'my $x = 42; say "same" if 42 = $x'
 Cannot modify an immutable Int

One could argue this should be spotted at compile time.


HTH,

Liz

Reply via email to