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

Strange MAIN positional string interpolations #5224

Open
p6rt opened this issue Apr 9, 2016 · 5 comments
Open

Strange MAIN positional string interpolations #5224

p6rt opened this issue Apr 9, 2016 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Apr 9, 2016

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

Searchable as RT127864$

@p6rt
Copy link
Author

p6rt commented Apr 9, 2016

From @MadcapJake

From IRC​:
9​:22 PM <MadcapJake> if I pass a : at the beginning of a string argument to MAIN, it fails to match any signatures and triggers the Usage message
9​:25 PM <ZoffixWin> MadcapJake, can't reproduce. What's the sig for MAIN you're using and what's the way you're calling the script with?
9​:25 PM <MadcapJake> ./bin/rabble -e -d "​: addone 1 + ; 1 addone ."
9​:26 PM <ZoffixWin> MadcapJake, but the usage message tells you to use -d="..." doesn't it? You're missing the equals sign
9​:26 PM <MadcapJake> no, those are Bools
9​:27 PM <MadcapJake> ~/github/rabble/bin/rabble --expression|-e [--debug|-d] <expr>
9​:27 PM <MadcapJake> ~/github/rabble/bin/rabble [--debug|-d] <file>
9​:28 PM <ZoffixWin> MadcapJake, confirmed on my box. You should rakudobug this​: perl6 -e 'sub MAIN ($x) {}' "​: 42" <-- triggers usage... perl6 -e 'sub MAIN ($x) {}' "42" <-- no usage
9​:28 PM <MadcapJake> :(Str $expr, Bool :expression(​:$e)!, Bool :debug(​:$d)) is the signature I'm trying to match
9​:29 PM <ZoffixWin> The bug seems to exist with a single positional as well. A "​:" as the first char in the positional breaks something
9​:33 PM <ZoffixWin> MadcapJake, are you rakudobugging it? I found this works​: to set $y to 45​: perl6 -e 'sub MAIN ($x, :$y) { say $y }' "​:y=45" 42
9​:34 PM <ZoffixWin> In addition it's also impossible to pass "-y=45" to a positional argument, because it gets interpreted as a named arg, it seems
9​:35 PM <teatime> ZoffixWin​: even if you do -- first ?
9​:35 PM <ZoffixWin> teatime, was about to say.... the -- is the way.
9​:35 PM <ZoffixWin> This is more about the shell than Perl 6, but :y should still be parsed as normal string and not a named arg IMO
9​:36 PM <ZoffixWin> perl6 -e 'sub MAIN ($x) { say $x }' -- "​:y=45" works fine
9​:36 PM <ZoffixWin> Unless there are some shells where : instead of - on args is used that I'm unaware of.

@p6rt
Copy link
Author

p6rt commented Apr 9, 2016

From @peschwa

On Fri Apr 08 19​:39​:49 2016, madcap.russo+p6@​gmail.com wrote​:

From IRC​:
9​:22 PM <MadcapJake> if I pass a : at the beginning of a string
argument to MAIN, it fails to match any signatures and triggers the
Usage message
9​:25 PM <ZoffixWin> MadcapJake, can't reproduce. What's the sig for
MAIN you're using and what's the way you're calling the script with?
9​:25 PM <MadcapJake> ./bin/rabble -e -d "​: addone 1 + ; 1 addone ."
9​:26 PM <ZoffixWin> MadcapJake, but the usage message tells you to use
-d="..." doesn't it? You're missing the equals sign
9​:26 PM <MadcapJake> no, those are Bools
9​:27 PM <MadcapJake> ~/github/rabble/bin/rabble --expression|-e [--
debug|-d] <expr>
9​:27 PM <MadcapJake> ~/github/rabble/bin/rabble [--debug|-d] <file>
9​:28 PM <ZoffixWin> MadcapJake, confirmed on my box. You should
rakudobug this​: perl6 -e 'sub MAIN ($x) {}' "​: 42" <-- triggers
usage... perl6 -e 'sub MAIN ($x) {}' "42" <-- no usage
9​:28 PM <MadcapJake> :(Str $expr, Bool :expression(​:$e)!, Bool
:debug(​:$d)) is the signature I'm trying to match
9​:29 PM <ZoffixWin> The bug seems to exist with a single positional as
well. A "​:" as the first char in the positional breaks something
9​:33 PM <ZoffixWin> MadcapJake, are you rakudobugging it? I found this
works​: to set $y to 45​: perl6 -e 'sub MAIN ($x, :$y) { say $y }'
"​:y=45" 42
9​:34 PM <ZoffixWin> In addition it's also impossible to pass "-y=45"
to a positional argument, because it gets interpreted as a named arg,
it seems
9​:35 PM <teatime> ZoffixWin​: even if you do -- first ?
9​:35 PM <ZoffixWin> teatime, was about to say.... the -- is the way.
9​:35 PM <ZoffixWin> This is more about the shell than Perl 6, but :y
should still be parsed as normal string and not a named arg IMO
9​:36 PM <ZoffixWin> perl6 -e 'sub MAIN ($x) { say $x }' -- "​:y=45"
works fine
9​:36 PM <ZoffixWin> Unless there are some shells where : instead of -
on args is used that I'm unaware of.

S19 specifies

  Options must begin with one of the following symbols​: --, -, or :.

So this is not up to the shell, but the interpreter.

Of course, that doesn't change that there's something weird. Consider the following examples​:

$ ./perl6-m --version
This is Rakudo version 2016.03-106-gd847011 built on MoarVM version 2016.03-104-g10d3971
implementing Perl 6.c.
$ ./perl6-m "--version"
This is Rakudo version 2016.03-106-gd847011 built on MoarVM version 2016.03-104-g10d3971
implementing Perl 6.c.
$ ./perl6-m -e'multi MAIN($a) { say "pos" }; multi MAIN(​:$a) { say "named" }' "​:a"
named
$ ./perl6-m -e'multi MAIN($a) { say "pos" }; multi MAIN(​:$a) { say "named" }' -- "​:a"
named
$ ./perl6-m -e'multi MAIN($a) { say "pos" }; multi MAIN(​:$a) { say "named" }' -- "--a"
named
$ ./perl6-m -e'multi MAIN($a) { say "pos" }; multi MAIN(​:$a) { say "named" }' "--a"
Illegal option --a
[rest of < perl6 --help > here]

The last case is probably the most interesting one... :)

In any case, what actually seems to be wrong is that the interpreter can't distinguish between quoted arguments that look like switches and non-quoted switches, and -- as "only arguments from here on" doesn't seem to work completely reliably either.

@p6rt
Copy link
Author

p6rt commented Apr 9, 2016

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

@p6rt
Copy link
Author

p6rt commented Apr 9, 2016

From @peschwa

S19 specifies

s/specifies/speculated/ ... :)

@p6rt
Copy link
Author

p6rt commented Apr 9, 2016

From paul@littlebluetech.com

There is also discussion / description here​:

https://design.perl6.org/S06.html#Declaring_a_MAIN_subroutine

@p6rt p6rt added the Bug label Jan 5, 2020
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

1 participant