Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of space after != operator changes behaviour #3322

Closed
p6rt opened this issue Jan 28, 2014 · 7 comments
Closed

Lack of space after != operator changes behaviour #3322

p6rt opened this issue Jan 28, 2014 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 28, 2014

Migrated from rt.perl.org#121108 (status was 'open')

Searchable as RT121108$

@p6rt
Copy link
Author

p6rt commented Jan 28, 2014

From @peschwa

The following test in roast currently is skipped for Rakudo as a nom regression​:

{
  # Check a 3 != 3 vs 3 !=3 parsing issue that can cropped up in Rakudo.
  # Needs careful following of STD to get it right. :-)
  my $r;
  sub foo($x) { $r = $x }
  foo 3 != 3;
  is($r, False, 'sanity 3 != 3');
  foo 3 !=3;
  is($r, False, 'ensure 3 !=3 gives same result as 3 != 3');
}

STD parses the comparision successfully​:

<psch> std​: 3 !=3
<camelia> std 09dda5b​: OUTPUT«ok 00​:01 122m␤»

while Rakudo tries to assign and fails​:

<psch> r​: say 3 !=3
<camelia> rakudo-parrot c884dc​: OUTPUT«Cannot modify an immutable value␤ in sub infix​:<=> at gen/parrot/CORE.setting​:16361␤ in block at gen/parrot/CORE.setting​:16706␤ in block at /tmp/tmpfile​:1␤␤»
23​:33 <camelia> ..rakudo-moar c884dc​: OUTPUT«No such method 'STORE' for invocant of type 'Int'␤ in sub infix​:<=> at src/gen/m-CORE.setting​:16092␤ in block at src/gen/m-CORE.setting​:16436␤ in block at /tmp/tmpfile​:1␤␤»
<camelia> ..rakudo-jvm c884dc​: OUTPUT«Cannot modify an immutable value␤ in sub infix​:<=> at gen/jvm/CORE.setting​:16095␤ in block at gen/jvm/CORE.setting​:16439␤ in block at /tmp/tmpfile​:1␤␤»

@p6rt
Copy link
Author

p6rt commented Mar 26, 2014

From @FROGGS

that STD says it is okay does not mean much here, because​:

./viv -e 'say 1 != 3'
[...]
└─VAST​::SYM_infix__S_BangEqual, BEG​: 6, END​: 8, SYM​: !=,
  TEXT​: !=, WS​: 1, _from​: 8, _op​: VAST​::infix__S_BangEqual,
  _pos​: 8, _specific​: 1, assoc​: chain, dba​: chaining,
  diffy​: 1, iffy​: 1, prec​: m=, pure​: 1
[...]

./viv -e 'say 1 !=3'
[...]
└─VAST​::SYM_infix__S_Equal, BEG​: 7, END​: 8, SYM​: =, TEXT​: =,
  _from​: 8, _op​: VAST​::infix__S_Equal, _pos​: 8,
  _specific​: 1, assoc​: right, dba​: list assignment,
  fiddly​: 1, prec​: i=, pure​: 0
[...]

So already STD has a problem here and I will open a STD-issue in its github repo, see​:
perl6/std#7

@p6rt
Copy link
Author

p6rt commented Mar 26, 2014

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 25, 2016

From @zoffixznet

If the programmer omits the space after the != (not equal, numeral) operator, the behavior of the operator changes to​: [assign RHS to LHS, return !RHS], as can be seen from these examples​:

<ZoffixW> m​: say 0 != 0
<camelia> rakudo-moar f05c77​: OUTPUT«False␤»
<ZoffixW> m​: say 0 !=0
<camelia> rakudo-moar f05c77​: OUTPUT«Cannot modify an immutable Int␤ in block <unit> at /tmp/7Z5OWfl3Go line 1␤␤»
<ZoffixW> m​: my $x = 42; say $x !=0; say $x
<camelia> rakudo-moar f05c77​: OUTPUT«True␤0␤»
<ZoffixW> m​: my $x = 0; say $x !=42; say $x
<camelia> rakudo-moar f05c77​: OUTPUT«False␤42␤»

This behaviour is confusing and probably not wanted by most programmers.

@p6rt
Copy link
Author

p6rt commented Apr 25, 2016

From @peschwa

On Mon Apr 25 09​:20​:43 2016, cpan@​zoffix.com wrote​:

If the programmer omits the space after the != (not equal, numeral)
operator, the behavior of the operator changes to​: [assign RHS to LHS,
return !RHS], as can be seen from these examples​:

<ZoffixW> m​: say 0 != 0
<camelia> rakudo-moar f05c77​: OUTPUT«False␤»
<ZoffixW> m​: say 0 !=0
<camelia> rakudo-moar f05c77​: OUTPUT«Cannot modify an immutable Int␤
in block <unit> at /tmp/7Z5OWfl3Go line 1␤␤»
<ZoffixW> m​: my $x = 42; say $x !=0; say $x
<camelia> rakudo-moar f05c77​: OUTPUT«True␤0␤»
<ZoffixW> m​: my $x = 0; say $x !=42; say $x
<camelia> rakudo-moar f05c77​: OUTPUT«False␤42␤»

This behaviour is confusing and probably not wanted by most
programmers.

This is a dupe of https://rt-archive.perl.org/perl6/Ticket/Display.html?id=121108, which is wrongly titled at the moment.

@p6rt
Copy link
Author

p6rt commented Apr 25, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the Bug label Jan 5, 2020
lizmat added a commit to rakudo/rakudo that referenced this issue Apr 1, 2022
As a follow-up on f3b1e95 Ralph Mellor++ pointed to
Raku/old-issue-tracker#3322 from 2014.
This turned out to be a similar issue.  Fixing this properly
would be a little more involved and potentially breaking, and
since this is all going to go in RakuAST anyway, fix this by
basically a simple hack to change '!=' effectively into '!=='.

Makes two TODO tests pass.
@lizmat
Copy link
Contributor

lizmat commented Apr 1, 2022

Fixed with rakudo/rakudo@12dd09e1b4

@lizmat lizmat closed this as completed Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants