El mié., 26 sept. 2018 a las 6:12, Todd Chester (<toddandma...@zoho.com <mailto:toddandma...@zoho.com>>) escribió:

    Hi All,

    https://docs.perl6.org/routine/words
    is no help

    Not to ask too obvious a question, but why does words use a []
    instead of a () ?

On 09/25/2018 10:38 PM, JJ Merelo wrote:




Are you referring to a particular example? I can't find it.

yes the ones in the original post.


At any rate, $whatever.words[4] is the same as $whatever.words()[4]. That method needs no arguments, so it makes do without parentheses. When it uses it, it's to limit the number of words returned.

Cheers

JJ


I am confused as to when to use [] and when to use () with a method.

The only thing can think of is that [] allows me to do thing like
   [4]
   [4,6]
   [4..6]
Where I can't do it with ()

But why is (4) different than [4]?

And
   https://docs.perl6.org/routine/words#class_Str
   (Str) routine words

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

Also is `Str:D $input:` written correctly?  I have only seen it as
`Str:D:` before.


-T

Reply via email to