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

Variable Prefix Miscount #4318

Open
librasteve opened this issue Jun 7, 2023 · 5 comments
Open

Variable Prefix Miscount #4318

librasteve opened this issue Jun 7, 2023 · 5 comments
Assignees
Labels
docs Documentation issue (primary issue type)

Comments

@librasteve
Copy link

Problem or new feature

This section https://docs.raku.org/language/variables#Variable_declarators_and_scope says...

There are also two prefixes that resemble declarators but act on predefined variables:

Prefix Effect
temp Restores a variable's value at the end of scope
let Restores a variable's value at the end of scope if the block exits unsuccessfully
constant Declares that a container value is not going to change during its lifetime

Suggestions

I count 3

;-)

@librasteve librasteve added the docs Documentation issue (primary issue type) label Jun 7, 2023
@coke
Copy link
Collaborator

coke commented Jun 7, 2023

good catch, thanks.

@coke
Copy link
Collaborator

coke commented Jun 7, 2023

66a7177

@coke coke closed this as completed Jun 7, 2023
@coke coke added this to the 2023-Quarter 2 milestone Jun 7, 2023
coke added a commit that referenced this issue Jun 7, 2023
@raiph
Copy link
Contributor

raiph commented Jun 7, 2023

That seems like the wrong fix.

Only temp and let act on a predefined variable. (constant declares one.)

Perhaps the constant row should have been in the previous table (and the "two" was correct)?

It's perhaps outside the, er, scope of this issue, but the text of that row is wrong:

Declares that a container value is not going to change during its lifetime.

I would strawman propose:

Declares a name that's immutably bound at compile time to whatever its initialized with.

@coke coke reopened this Jun 8, 2023
@coke coke assigned coke and raiph Jun 8, 2023
@librasteve
Copy link
Author

I like @raiph proposals on constant

@librasteve
Copy link
Author

Since this is the only place I have (ever) seen let and temp, I am curious about their typical use, so this could use a bit more explanation.

Maybe something like:

my $a = 1;

{
    temp $a = 2;
    say $a;   #2  
}

say $a;  #1  

and this

my $b = 1;

{
    let $b = 2;
    say $b;   #2  
}

say $b;  2#

So another concern is that let and temp are called 'Prefix's BUT they are not used as a prefix to the declaration.

Elsewhere I would say that e.g. my is a prefix for my class A {} or e.g. our is a prefix for our sub(). So maybe better to call let and temp "Modifiers".

And perhaps some admonishment to using the form let my $a =1 since that is accepted by the compiler, but is contrary (aiui) to the intent.

@coke coke removed their assignment Jun 29, 2023
@coke coke modified the milestones: 2023-Quarter 2, 2023-Quarter 3 Jul 12, 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
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

3 participants