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

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

Attachment: signature.asc
Description: PGP signature

Reply via email to