On Sun, Jun 07, 2020 at 06:19:29PM +0300, Peter Pentchev wrote:
> On Sun, Jun 07, 2020 at 09:04:45AM -0500, Brad Gilbert wrote:
> > On Sun, Jun 7, 2020 at 3:15 AM ToddAndMargo via perl6-users <
> > perl6-us...@perl.org> wrote:
> > 
> > > Hi All,
> > >
> > > Dumb question:
> > >
> > > Does the "multi" in "multi method" mean there
> > > is more than one way to address a method?
> > >
> > > Or, are the all methods "multi methods".
> > >
> > > If not and the method is a multi, should not the
> > > documentation show all (more than one) the ways of
> > > addressing a multi method?
> > 
> > There are four different types of a function. (both method and sub)
> > 
> > - `multi`
> > - `proto`
> > - `only`
> > - `anon`
> > 
> > A `proto` function is mainly just to declare there will be multiple
> > functions with same name.
> > `multi` is short for "multiple", meaning more than one.
> > `only` is the default, it means there is only one.
> > `anon` is for creating a lambda. (You only need it if you give the function
> > a name.)
> > 
> > Again this applies to both subs and methods.
> > (Also `regex`, `token`, and `rule`. As they are just special methods.)
> > 
> >     only sub foo (){}
> >     only sub foo (1){} # ERROR: redeclaration
> >     # note that `only` is optional, as it is the default.
> > 
> >     proto sub bar (|){*}
> >     multi sub bar (){}
> >     multi sub bar (1){}
> >     # note that defining a `proto` function is optional
> > 
> >     my $var = anon sub baz (){ 'fuzz' };
> >     say baz(); # ERROR: can't find a sub named `baz`
> >     say $var(); # fuzz
> >     say $var.name; # baz
> 
> I believe, though I'm not sure, that Todd may be referring to one of
> the questions that came up in a longish recent thread, namely the fact
> that the documentation of Str.starts-with() seems to only document it as
> a Str method, while Raku seems to disagree:
> 
> [roam@straylight ~]$ raku -e 'my Str $x; $x.starts-with("a")'
> 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 ~]$
> 
> So it seems that Cool has a .starts-with() method too, and this is borne
> out by a further experiment:
> 
> [roam@straylight ~]$ raku -e 'my Cool $x; $x.starts-with("a")'
> Cannot resolve caller starts-with(Cool: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)
>   in block <unit> at -e line 1
> 
> [roam@straylight ~]$
> 
> So the truth is that I do not fully understand why the documentation
> does not list .starts-with() as a method for Cool as well as Str: in
> https://docs.raku.org/routine.html "starts-with" is listed as "from
> Str", while there are other methods that are listed as "from Cool, Str",
> e.g. "subst".
> 
> Now, yeah, I understand that Str.starts-with() defines a coercion for
> its $needle argument that means that Cool.starts-with() will never be
> called for an invocant that is either a Str or of any type derived from
> Str, no matter what $needle is - if it is from another Cool-derived
> type, it will be coerced to Str and Str.starts-with() will be called.
> However, should the documentation not mention that another type derived
> from Cool will also have a .starts-with() method?
> 
> Please note that I'm not criticizing the documentation, automatically
> generated or not, or the efforts of everyone involved in producing it :)
> I am under the impression that it is, at least to some extent,
> automatically generated, so I'm genuinely curious what is it about
> the .starts-with() method that has caused it to lose its Cool :)
> 
> ...and, of course, it may turn out that Todd meant something completely
> different in this particular message and I hijacked the thread...

Ah nevermind, I figured it out. Stupid me!

That *is* what Cool does!

That is the whole purpose Cool - to coerce its invocant to a specific
type, depending on what method is called. So, yeah, if somebody invokes
.starts-with() on an object of a type that is derived from Cool, yet is
not Str, the Cool.starts-with() method will try to coerce the invocant
itself to Str and, thus, invoke Str.starts-with() :)

OK, so I get it now, I guess whatever generates the documentation knows
that Cool is way, way special, and knows that there is no point in
describing Cool.starts-with(), since all it does is invoke
Str.starts-with() if there is nothing more specific. Sorry for the
noise... so I learned something today, and, TBH, it's really nice of
the documentation generator to do this particular thing, omitting
the description of a method that really merits none.

Sorry for the noise, and keep up the great work!

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