On Mon, Jun 01, 2020 at 01:36:19PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-06-01 02:21, Peter Pentchev wrote:
> > On Mon, Jun 01, 2020 at 01:15:23AM -0700, ToddAndMargo via perl6-users 
> > wrote:
> > > On 2020-05-31 17:13, Peter Pentchev wrote:
> > > > On Mon, Jun 01, 2020 at 03:12:05AM +0300, Peter Pentchev wrote:
> > > > > On Sun, May 31, 2020 at 04:29:55PM -0700, ToddAndMargo via 
> > > > > perl6-users wrote:
> > > > > > On 2020-05-31 04:58, Peter Pentchev wrote:
> > > > > > > > > So my beef is when you feed these guys an undefined
> > > > > > > > > variable, that they needs to tell you it requires
> > > > > > > > > a "defined" variable.  Not a bunch of useless rubbish.
> > > > > > > > > For example (useless rubbish):
> > > > > > > And also... I thought I mentioned this before. You want a more 
> > > > > > > clear
> > > > > > > error message for*one*  *single*  specific case of a "can't find 
> > > > > > > this
> > > > > > > method, did you mean one of these?" error message. I tried to 
> > > > > > > explain
> > > > > > > that this error message is one that is displayed in many cases, 
> > > > > > > not only
> > > > > > > for "you passed an undefined thing, I want a defined thing"; in my
> > > > > > > opinion, it is actually quite helpful in that it actually lists
> > > > > > > the candidates in a "did you mean one of these?" style.
> > > > > > > 
> > > > > > > You want it to be clear if you pass an undefined value where a 
> > > > > > > defined
> > > > > > > value was expected; that would mean that somebody would have to 
> > > > > > > write
> > > > > > > the code to make it check whether it is this very specific case 
> > > > > > > and then
> > > > > > > that code would have to be maintained for years and years. 
> > > > > > > Tomorrow
> > > > > > > you'll say "but can't it give me a more clear message when I pass 
> > > > > > > an
> > > > > > > integer and it expected a string?" and the day after tomorrow 
> > > > > > > you'll say
> > > > > > > "but can't it give me a more clear message when I pass a string 
> > > > > > > and it
> > > > > > > expected a function?".
> > > > > > > 
> > > > > > > The error message says "you passed an object of this type, and I 
> > > > > > > can't
> > > > > > > find this method for this type; here are a couple of types that 
> > > > > > > have
> > > > > > > this method, did you mean one of these?"  It tells you what the 
> > > > > > > types
> > > > > > > are, and it doesn't have to have thousands of special cases. It 
> > > > > > > tells
> > > > > > > you what the types are.
> > > > > > 
> > > > > > Hi  Peter,
> > > > > > 
> > > > > > I like that you in-line and bottom post.  You are a lot
> > > > > > easier to follow.
> > > > > > 
> > > > > > I think are talking at cross purposes.  Let me give an
> > > > > > example:
> > > > > > 
> > > > > > Q: is a "cow" a "Plant"?
> > > > > > A: a "cow" in not a hazel nut
> > > > > > A: a "cow" in not a radish
> > > > > > A: a "cow" in not a carrot
> > > > > > A: a "cow" in not a cabbage
> > > > > > ...
> > > > > > 
> > > > > > Are all of the answers a correct?
> > > > > > Yes.. Evey answer is completely correct.
> > > > > > 
> > > > > > Are any of the answers helpful?
> > > > > > No
> > > > > 
> > > > > Right. So, once again, just as I said, you are only interested in one 
> > > > > of
> > > > > the answers - "Str:U is not a Str:D, you want a Str:D". However, how
> > > > > should Raku know *which* one of the answers you are interested in?
> > > > > Tomorrow you may pass an integer to a function that only accepts 
> > > > > strings
> > > > > and floating-point numbers; should Raku tell you "you must pass a
> > > > > string, not an integer" or "you must pass a floating-point number, not
> > > > > an integer"? Raku doesn't know which one of those you meant.
> > > > 
> > > > ...accepts strings *or* floating-point numbers, of course...
> > > > 
> > > > G'luck,
> > > > Peter
> > > > 
> > > 
> > > 
> > > Hi Peter,
> > > 
> > > I screw up A LOT.  When something REQUIRES "Str:D" and I
> > > send it a "Str:U", I want to be told such.  Not all
> > > the things it can't do, which I see thrashing around the
> > > protuberance of the scrubbary.
> > > 
> > >       starts-with's invocant requires a defined value (Str:D)
> > > 
> > > would be perfect.  Not appreciated is a list of all the
> > > things it can't do.  This makes me have to BOTH troubleshoot
> > > my screw up and the everything it can't do error message.
> > > 
> > > I think what you are trying to do is help me fix my screw
> > > ups, which is of course, much appreciated.  You are trying
> > > to help me understand what the error message means.
> > > 
> > > What I am after in this thread is a better error message.
> > > 
> > > Thank you for all the help and tips.
> > > 
> > > -T
> > > 
> > > p.s believe me, there will be a lot more screw ups on my
> > > part in the future for you to help me fix!  Of that you
> > > can rest assured.
> > 
> > OK, so for the last time :)
> > 
> > Imagine the following code:
> > 
> > ===================================================
> > 
> > #!/usr/bin/env raku
> > 
> > use v6.d;
> > 
> > class Thing {
> >     multi method do-things(Int:D $value) {
> >             say "A thing can do things with an integer: $value";
> >     }
> > 
> >     multi method do-things(Rational:D $value) {
> >             say "A thing can do things with a rational number: $value";
> >     }
> > }
> > 
> > my Thing:D $thing = Thing.new;
> > 
> > dd $thing;
> > 
> > $thing.do-things(5);
> > $thing.do-things(3/5);
> > 
> > # And now for the clincher...
> > $thing.do-things("what?!");
> > 
> > ===================================================
> > 
> > Running it on my system does this:
> > 
> > [roam@straylight ~/tmp/v/roam/testwhee]$ raku functions.raku
> > Thing $thing = Thing.new
> > A thing can do things with an integer: 5
> > A thing can do things with a rational number: 0.6
> > Cannot resolve caller do-things(Thing:D: Str:D); none of these signatures 
> > match:
> >      (Thing: Int:D $value, *%_)
> >      (Thing: Rational:D $value, *%_)
> >    in block <unit> at functions.raku line 23
> > 
> > [roam@straylight ~/tmp/v/roam/testwhee]$
> > 
> > In other words, Raku tells me "I don't know which of these methods you 
> > want".
> > It doesn't know.
> > 
> > You say "it should tell me exactly what to do" - well, what exactly
> > would you like Raku to tell you in this case? Should it assume that you
> > meant to pass an integer? Should it assume that you meant to pass a
> > rational number?
> > 
> > It cannot tell you anything more specific.
> > It just... doesn't... know.
> > You are the only one who knows what you're *trying* to do. Raku doesn't.
> > 
> > Hope that helps :)
> > 
> > G'luck,
> > Peter
> > 
> 
> Hi Peter,
> 
> We are on the same page.  I still think they could
> improve their error message.  If they are checking
> the earth, moon, and stars, they can easily add
> defined as one of their tests.  It is better to inform
> you what actually is wrong rather than listing what
> is can not do.

Right after hitting "Send" (well, right after hitting ':wq' and 'y', but
that's an implementation detail :), I realized you'd say that, so
I immediately wrote another message explaining why I think they did that.
I explicitly said "it may seem to you that it would be easy"... but
it's not. If you have more to say on this, you might want to respond to
that message and address the arguments there.

> A follow up question:
> 
> Is there a booboo in the documentation here?
> 
> https://docs.raku.org/routine/starts-with
> multi method starts-with(Str:D: Str(Cool) $needle, :i(:$ignorecase),
> :m(:$ignoremark) --> Bool:D)
> 
> It says "multi method" but only shows one method.
> Did they leave something out?

Mmm, and this is where we come to the original error message :)
It says that there is a "starts-with()" method in the Str class that
accepts a "$needle" parameter of the Str:D type, but then (or, rather,
before that) it says that there is a "starts-with()" method in the Cool
class that accepts a "$neddle" parameter of the Cool:D type. Since Str
is derived from Cool, when you call a method on Str Raku will also look
for this method in Cool. Since the two methods accept parameters of
different types, they (or at least the method in the child class Str)
have to be declared as multi methods so Raku knows that a type mismatch
on the first one that it found does not mean that it should stop
looking.

But, hm, why the documentation of the starts-with() method on the page
that you linked to does not mention that it is also present in Cool is
indeed an interesting question. Moreover, even the list of methods at
https://docs.raku.org/routine-method.html says "method starts-with()
from Str", while other methods such as subst() are listed as "from Cool,
Str", etc. I honestly don't know what the difference is, I expect it is
because of some internal details of the implementation of the Str
method, but I won't be able to look it in the source right now. Maybe
somebody else could shed some light on that?

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