On 11/09/18 12:23, ToddAndMargo wrote:
> As I understand it $needle? is the second optional parameter
> and it is an integer, not "Cool" (both a string and a number).

Where did you get "$needle?" from? I'm looking at the docs for method
"contains" of type Str right now and it only says that $pos is optional.

The : after Str:D means that it applies not to a parameter you put into
the parenthesis, but to the object you're calling the method on.

That means that $needle is actually the first parameter, not the second one.

> I presume "Cool" includes real numbers too.

Yes, types that are derived from Cool can be coerced to numbers, or strings.

> I have no idea how they got from
>
> multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
>
> to
>
> $ p6 'say "abc".contains("b");'
> True

I hope the comments I made above made this a little clearer.

I also see that the paragraph directly below the different multi
candidates in the docs mention how the Str:D: works, as well. Though
that page was last edited only 23 hours ago, so maybe you're looking at
an outdated page?

> Perl 6's function reference has got to be the hardest
> to understand I have ever come across.  Perl 5's
> "perldocs -v" were a bazillion times easier to understand.
>
> -T

Understanding signature syntax is very important, and the signature
syntax alone already tells you a lot about how a sub or method works.
Since the signatures are so expressive, they can of course also be "a
bit much" to understand, unfortunately.

Hope that helps
  - Timo

Reply via email to