On 9/26/18 10:47 AM, The Sidhekin wrote:
On Wed, Sep 26, 2018 at 8:58 AM Todd Chester <toddandma...@zoho.com <mailto:toddandma...@zoho.com>> wrote:

    Hi All,

    Over on
    https://docs.perl6.org/routine/words
    I see

         multi method words(Str:D $input: $limit = Inf --> Positional)

    HOW IN THE WORLD did they convert `$limit = Inf` into an
    array index!?!?!


   It's not.  It's a limit:

eirik@greencat[19:41:18]~$ perl6 -e '.say for "foo bar baz qux".words(2)'
foo
bar
eirik@greencat[19:41:29]~$

  I see from your other email that you're using square brackets. That's what makes a zero-based index:

eirik@greencat[19:41:29]~$ perl6 -e '.say for "foo bar baz qux".words[2]'
baz
eirik@greencat[19:43:00]~$

  But this index is not an argument to the words method.  It is an argument to the .[ ] postcircumfix.

  That these are different things is perhaps more easily seen when they're both present:

eirik@greencat[19:45:54]~$ perl6 -e '.say for "foo bar baz qux".words(3)[*-1]'
baz
eirik@greencat[19:45:59]~$

   Here, it may be clearer that the $limit is 3, and the index is *-1.


Eirik


Hi Eirik,

Thank you for the explanation.

I think I did  not make myself clear.  I do know how to
use the function and I use it all the time.

What I don't understand is:

     multi method words(Str:D $input: $limit = Inf --> Positional)

Specifically "$limit = Inf".  Why are we using "$limit" instead
of "$selection" and why are we throwing "Inf" into the mix
as it is a "type".  "Types" are written like "Str:D" and come
before the variable, not after.  (I know the ":D" means "defined".)

And where is it stated what goes in the () and what goes
in the []?

Yours in frustration,
-T

Reply via email to