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

%0 and &0 should probably be syntax errors #44

Closed
lizmat opened this issue Jun 19, 2019 · 2 comments
Closed

%0 and &0 should probably be syntax errors #44

lizmat opened this issue Jun 19, 2019 · 2 comments
Assignees
Labels
language Changes to the Raku Programming Language

Comments

@lizmat
Copy link
Collaborator

lizmat commented Jun 19, 2019

This started off with:

$ perl6 -e 'my $width = 4; printf("%0{$width}d", 42)'
Use of uninitialized value element of type Any in string context.
Methods .^name, .perl, .gist, or .say can be used to stringify it to something meaningful.
  in block <unit> at -e line 1
Your printf-style directives specify 0 arguments, but 1 argument was supplied
  in block <unit> at -e line 1

which, in my view, is a completely legit way of specifying a variable width printf format.

Turns out, this does not do what you mean. Apparently, this is short for %($/[0]).

$ perl6 -e '"abcd" ~~ m/(\w)+/; say %0'
{a => 「b」, c => 「d」}

which looks nice, but with an odd number of captures, becomes:

$ perl6 -e '"abc" ~~ m/(\w)+/; say %0'
Odd number of elements found where hash initializer expected:
Found 3 (implicit) elements:
Last element seen: Match.new(list => (), from => 2, hash => Map.new(()), made => Any, pos => 3, orig => "abc")
  in block <unit> at -e line 1

It even gets weirder with &0:

$ perl6 -e '"abc" ~~ m/(\w)+/; say &0'
[「a」 「b」 「c」]

which, btw is also what @0 and $0 give.

I propose that %N and &N (where N is a 0..Inf) do not interpolate, and become syntax errors outside of interpolation.

@AlexDaniel AlexDaniel added the language Changes to the Raku Programming Language label Jun 19, 2019
@AlexDaniel
Copy link
Member

AlexDaniel commented Jun 19, 2019

FWIW, I didn't even know that @0 %0 &0 are allowed.

@lizmat
Copy link
Collaborator Author

lizmat commented Jun 19, 2019

I didn't either until someone pointed it out to me in a mail. @0 kinda makes sense, for the given example. %0 and &0 definitely do not, in my opinion.

@lizmat lizmat closed this as completed May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language Changes to the Raku Programming Language
Projects
None yet
Development

No branches or pull requests

3 participants