On 2020-05-31 16:21, Peter Pentchev wrote:
On Sun, May 31, 2020 at 04:06:28PM -0700, ToddAndMargo via perl6-users wrote:
On 2020-05-31 12:48, Veesh Goldman wrote:
well, literally it would mean something like "a direct result of
inability to read is to not understand", which in context should mean if
you can't read you won't understand. But I think the point was made.


Hi Veesh,

Please help me with my reading skills here.

https://docs.raku.org/routine/starts-with

multi method starts-with(Str:D: Str(Cool) $needle, :i(:$ignorecase),
:m(:$ignoremark) --> Bool:D)

Does this or does this not state that the "Haystack"
(invocant) is required to be defined ("Str:D:")?

Yes, it does. Good!

If I am reading it correctly, is requires a "defined"
("D") Haystack (invocant).  Am I misreading something?

No, you're not - or at least, only slightly, see below.

Running a test, the method DO NOT check for defined:

     p6 'my $x; say $x.starts-with( "1" );'
     No such method 'starts-with' for invocant of type
     'Any' in block <unit> at -e line 1
What am I misreading?  Does it say anywhere that the
Haystack in not defined? Does it way anywhere that I
violated the requirement that the Haystack be defined?

And what is "No such method 'starts-with'" suppose to
mean?  I am staring at the method on right on the manual
page.  Did the developers forget to include "opens-with"
on my version of Raku?  Obvious it does not mean what
it says.  Unless my reading skill really suck.

Try it with something slightly different, give Raku something to
work with :)

[roam@straylight ~]$ raku -e 'my Str $x; $x.starts-with("1")'
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 -e line 1

[roam@straylight ~]$

The difference is that you said "my $x", thus making $x an undefined
variable of the "Any" type (since you did not specify a type), and
I said "my Str $x", thus making $x an undefined string. Once Raku knows
that $x is supposed to be a string, it can look for a .starts-with()
method in the Str class and in all its parent classes - and it finds
some methods in Str and some methods in the class named Cool.

Also, lets add to my reading comprehension, the Needle:
    `Str(Cool) $needle`

I do not see "D" or "U" anywhere.  Am I missing something?

A test:
      $ p6 'my $x; say "abc".starts-with( $x );'
      Cannot resolve caller starts-with(Str:D: Any:U);
      none of these signatures match: ...

Hm, this one is interesting. On the one hand, your test was once again
slightly wrong, once again you should have declared $x to be a Str.
On the other hand, even with the corrected test:

[roam@straylight ~]$ raku -e 'my Str $x; dd "abc".starts-with($x);'
Cannot resolve caller starts-with(Str:D: Str:U); 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 -e line 1

[roam@straylight ~]$

And here we come to the interesting part: it seems that the
documentation is wrong here, since what Raku says is that the
.starts-with() method of the Str class really wants a `Str:D $needle` -
it does expect its argument to be defined.

Okay, now it tells me "Any:U" for the needle.  It
is telling me that I sent it a undefined value.  To
me, that is a good troubleshooting hint.  Am I
misreading it?

Well, it's actually telling you that you *passed* an Any:U object :)
Yes, it's telling you that it cannot find a method .starts-with() that
will accept an undefined object of the "Any" type as a parameter,
so, yeah, getting close :)

Now what I would "like to see" (suggestion, not a demand),
is the Haystack complain in a similar fashion.  For instance:

     starts-with's invocant requires a defined value (Str:D)

Have I misread anything?

See above - you'll get this if you declare $x as a Str :)
But, yes, you're making progress, great!

G'luck,
Peter


Hi peter,

Close to you too.  The test were deliberate misuse
to slow the result.   This is about how to
troubleshoot what comes back when I screw up.

And the answers coming back are telling me what it
can't do rather than what is wrong.  In other words,
I have to BOTH what did wrong and what the error message
is suppose to mean.

-T

Reply via email to