On 2020-05-28 06:39, Peter Pentchev wrote:
On Wed, May 27, 2020 at 03:12:01PM -0700, ToddAndMargo via perl6-users wrote:
On 2020-05-27 14:32, Andy Bach wrote:
#!/usr/bin/env raku
my Str $x;
if $x.starts-with( "[" ) &&
$x.contains( "]" )
{ say "Passed"; } else { say "Failed"; }
K:\Windows\NtUtil>raku Contains.Test.pl6
Cannot resolve caller starts-with(Str:U: Str:D); none of these
signatures match
(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_
--> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
(Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ -->
Bool)
(Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Str:D: Str:D $needle, *%_ --> Bool)
in block <unit> at Contains.Test.pl6 line 3
> The function should just complain that the variable is not initialized.
Well, it is:
Cannot resolve caller starts-with(Str:U: Str:D);
...
in block <unit> at Contains.Test.pl6 line 3
it says:
For line 3:
if $x.starts-with( "[" )
looking for a possible method 'starts-with' with a signature of 2
params; an undefined string ('Str:U:') and a defined one ('Str:D:')
failed - here's the list of the possible signatures raku currently has
..."
I'd not be surprise if you could write your own "starts-with(Str:U:
Str:D); " method in raku and take care of this. You could probably even
have it "say"
You have an undefined String var in this call, not going to be able to
do much useful matching against that. Did you forget to initialize
something?
Hi Andy,
The function should just complain that you need to feed it an
initialized value instead of sending you on a wild goose chase,
It does say that you are trying to call "starts-with()" as a method on
a value of type Str:U (undefined string), and it cannot find such
a method. It also tells you what methods it can find.
It gives the same error message no matter what types the function/method
can handle and no matter what type you are trying to call it on.
From that point on Raku kind of expects you to know what Str:U means and
that the :U part means "undefined". It would give the same *type* of
message if you were trying to call a method that only works on undefined
strings and you were trying to call it on a defined string, only then it
would say that it can't find such a method for Str:D. In the eyes of
Raku, these errors are of the same kind, and it has provided you with
the types.
G'luck,
Peter
Hi Peter,
No doubt it is operating as designed.
It would be a lot more friendly if "Str:U" was
changed to "Str:D". Oh please! Oh Please!
Then the error message would be a lot more useful.
-T