On 09/11/2018 03:14 AM, Timo Paulssen wrote:
The colon at the end of "Str:D:" signifies that it's a type constraint on what you call the method on. For example:

my Str $foo;
$foo.contains("hello", 0);

won't work because $foo is currently not defined, i.e. doesn't pass the :D constraint. The : at the end means that the constraint "Str:D" applies to what's before the method call, in this case $foo.

In this signature, the needle is not optional, and it doesn't make sense to me to have it optional. What would it mean to ask if a string contains, but not what it's supposed to contain?

Without having to look at the docs, I would expect $pos to mean the position in the string that should be checked for presence of the needle (as in: find a needle in a haystack).

The return value isn't shown in this definition, but I'd say that's an oversight that should be fixed.

I hope that helps!
   - Timo


On 11/09/18 12:09, ToddAndMargo wrote:
multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)

Okay, I know that
   Str is a string
   Cool is an object that can be treated as both a string and a number
   $needle is the second optional parameter

What is "D"?

$needle is optional, why is it not stated as "$needle?"

How is both Str:D: and Cool:D the first parameter?

Why does "Str:D:" have a colon on the end and "Cool:D" does not?

What is Int(Cool:D) ?

What is $pos ?

Where is it stated that it has a return a value?

Where is it state that the return value is a boolean?

Yours in confusion,
-T



A little bit.  Thank you!  I will have to read it over several times.
Thank you.

As I understand it $needle? is the second optional parameter
and it is an integer, not "Cool" (both a string and a number).

I presume "Cool" includes real numbers too.


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

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


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to