-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
MAIN
: Str
arguments do not accept True
or False
#2794
Comments
I assume the order of the arguments was intended to be: So that Nil => "Nil", True -> "True", etc... |
Looks like the most obvious solution would be to introduce a |
Having an |
Indeed; that's what I get for noticing the prose would work better if I'd thought to put I've edited to fix. Apologies for the confusion. |
There's one more thorn in the side which EnumStr needs to fix:
From the results shown in the |
I think an 'EnumStr' is a requirement, actually, after considering this example: % ./cat-p6 *
@*ARGS is ["cat-p6"]
=== cat-p6 ===
#!/usr/bin/env perl6
unit sub MAIN(*@files);
say '@*ARGS is ', @*ARGS.perl;
for @files -> $f {
say "=== $f ===";
put $f.IO.lines.join("\n");
}
% for file in 42 hi True Bool::True; do
for> echo "This is $file" > $file
for> done
% ls
42 Bool::True True cat-p6 hi
% ./cat-p6 *
@*ARGS is ["42", "Bool::True", "True", "cat-p6", "hi"]
=== 42 ===
This is 42
=== True ===
This is True
=== True ===
This is True
=== cat-p6 ===
#!/usr/bin/env perl6
unit sub MAIN(*@files);
say '@*ARGS is ', @*ARGS.perl;
for @files -> $f {
say "=== $f ===";
put $f.IO.lines.join("\n");
}
=== hi ===
This is hi Without taking over |
I think
What should this do for |
On 25 Mar 2019, at 19:50, Nick Logan ***@***.***> wrote:
I think EnumStr would end up in confusion. Consider:
sub MAIN($s) {
if $s {
say 42
}
}
What should this do for Planned and Same? Is it the same behavior that would be used for False? Must developers be aware of all of these details, and that should explicitly coerce everything in their signatures when possible? I'm not sure a consistent behavior can be achieved.
That same argument goes for IntStr:
$ 6 'say "foo" if IntStr.new(0,"0”)’ # no output because 0 == False
as in the Str meaning only applies if there is no reasonable other meaning?
|
I can't think of a use case for passing non-string Planned, Kept, Broken, Less, More, or Same. I can almost buy Ideally MAIN should coerce to the declared type, or that to get
|
I concur. This abstraction is more than leaky.
That is generally a decent idea, but fails badly when passing an argument multiple times:
In other circumstances that can be worked around with |
This issue affacts all these values
This also means that, for example, one currently can't install a module with any such name via zef |
The problem is that even if you specify # Explicitly coerce to Int
sub MAIN(Int() $a) { say $a.WHAT } It will happily consume a string and keep it as Weirdly enough, though, the same reasoning doesn't apply (and possibly never did) for coercion methods themselves, therefore I don't know if there is an issue for this or not but this also seems much rather a design topic than a "simple matter of programming". |
That makes sense, for |
This is kind of a different topic but it is kind of unexpected that for something that is an The part that does belong here is that allomorphs have multiple ways to bite you: not only because an infinite amount of inputs can evaluate to boolean |
I think that a |
It's not well documented, but setting that to |
Honestly, in a language like Raku which is perfectly willing to coerce types for operators, and has a very loose sense of what I have been thinking about this a lot but the only thing that has ever appeared to me was that this allows "weak typing" for method calls as well, just like for |
I can imagine the use-case for dualvars such as $*USER (though I find even that a bit dubious), but it has never made sense to me for either command line argument handing and for It's a case of "this makes easy things easier but hard things harder" IME. |
The allomorphs are more than just for
And
Now, I can totally see |
The Problem
MAIN
:Str
arguments do not acceptTrue
orFalse
Expected Behavior
(Or, possibly the last two should be a currently-missing
BoolStr
allomorph or a compound type of some sort.)Actual Behavior
If
Str
is replaced withStr()
, this works much as would have been expected:I think that, in the context of
MAIN
, aStr
argument should always accept anything from a non-validating CLI like a Unix or Windows shell, so theStr()
should, perhaps, be implicit.Steps to Reproduce
See above for examples that can be directly entered into the shell.
Environment
perl6 -v
): This is Rakudo Star version 2018.10 built on MoarVM version 2018.10implementing Perl 6.c.
The text was updated successfully, but these errors were encountered: