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

error when binding variables #3908

Open
random-bites opened this issue Jun 21, 2021 · 6 comments
Open

error when binding variables #3908

random-bites opened this issue Jun 21, 2021 · 6 comments
Labels
docs Documentation issue (primary issue type)

Comments

@random-bites
Copy link

random-bites commented Jun 21, 2021

The Binding section of the Container documentation has the following example.

You can also bind variables to other variables:

my $a = 0;
my $b = 0;
$a := $b;
$b = 42;
say $a; # OUTPUT: «42␤»

However, when I attempt to repeat this example in the rakudo REPL, I get the following error.

my $a = 0;
my $b = 0;
$a := $b;
===SORRY!=== Error while compiling:
Cannot use bind operator with this left-hand side
------> $a := $b;
$b = 42;
42
say $a;
0

Who is right? The documentation or the compiler?

@random-bites random-bites added the docs Documentation issue (primary issue type) label Jun 21, 2021
@random-bites
Copy link
Author

The binding operator documentation has this example.

my $a = 42;
my $b := $a;
$b++;
say $a;

So, perhaps the variable binding example, in the Container Binding section, should have been written as follows?

my $a = 0;
my $b := $a;
$b = 42;
say $a; # OUTPUT: «42␤»

@JJ
Copy link
Contributor

JJ commented Jun 21, 2021

I'll have to check. This is one of the cases where the REPL might behave in a slightly different way. Thanks anyway for the report.

@random-bites
Copy link
Author

Okay, I compiled the following code from a .raku script without errors. Raku and rakudo are new to me, so I didn't realize that there might be different errors when compiling a .raku script vs. using the REPL. Especially, when the code appears so simple.

my $a = 0;
my $b = 0;
$a := $b;
$b = 42;
say $a; # OUTPUT: «42␤»

@JJ
Copy link
Contributor

JJ commented Jun 22, 2021

Any way, we should probably try and use code that works the same in the two places, or simply add a warning. Thanks for the report anyway.

@b2gills
Copy link
Contributor

b2gills commented Jun 23, 2021

This is one of the problems with the REPL.

Which is why I often write the entirety of my code on a single line, in an enclosing block

> { my $a = 42; my $b := $a; $b++; say $a; }
43

Another such problem is that operators often don't work correctly either.

> sub postfix:<!> (UInt \n) {[×] 1..n}; say 5!
120
> say 5!
===SORRY!=== Error while compiling:
Negation metaoperator not followed by valid infix
------> say 5!⏏<EOL>
    expecting any of:
        infix
        infix stopper
> 

Every time you press enter it creates a new execution environment. The way it currently does it has its issues.

@coke coke self-assigned this Jun 23, 2021
@coke
Copy link
Collaborator

coke commented Jun 23, 2021

Looking for a place to document the potential issue with the REPL (there isn't really a good one at the moment), I found a footnote here describing a similar problem:

https://docs.raku.org/language/variables#fn-ref-1

I don't think every example that has trouble in the REPL needs a footnote; my recommendation is to add a single warning to the REPL docs.

@coke coke removed their assignment Jun 23, 2021
@coke coke self-assigned this Nov 15, 2022
@coke coke added this to the 2023-Quarter 2 milestone Mar 2, 2023
@coke coke modified the milestones: 2023-Quarter 2, 2023-Quarter 3 Jul 12, 2023
@coke coke removed their assignment Aug 15, 2023
@coke coke modified the milestones: 2023-Quarter 3, 2023-Quarter 4 Oct 8, 2023
@coke coke modified the milestones: 2023-Quarter 4, 2024-Quarter-2 Mar 31, 2024
@coke coke modified the milestones: 2024-Quarter-2, 2024-Quarter-3 Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

4 participants