On 9/26/18 4:33 PM, The Sidhekin wrote:
On Wed, Sep 26, 2018 at 11:40 PM ToddAndMargo <toddandma...@zoho.com <mailto:toddandma...@zoho.com>> wrote:

    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"

  Perhaps this would be easier if you explain where you're getting "$selection", and what you think it is.

$ p6 '"a b c d e".words[ 2, 4 ].say;'
(c e)

or

$ p6 '"a b c d e".words()[ 2, 4 ].say;'
(c e)

I am selecting the 2nd and 4th word starting from zero.  Inside
the brackets I am asking it to select th e 2nd and 4th words for me.

I am NOT asking it to limit my request to Infinity.




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


  The () is part of a method call syntax; method arguments go there: https://docs.perl6.org/language/syntax#Subroutine_calls

Where does it state that

$ p6 '"a b c d e".words(3).say;'
(a b c)

means the first three words, starting at zero?


  The [] is a postcircumfix operator; index arguments go there: https://docs.perl6.org/language/operators#postcircumfix_[_]

Where does

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

state that I can do such?

I ask this because not all methods will take []


$ p6 '"a b c d e".contains( "a","b" ).say;'
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏b' (indicated by ⏏)
  in block <unit> at -e line 1

$ p6 '"a b c d e".contains( 1, 3 ).say;'
Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
:(Str:D: Cool:D $needle, Cool:D $pos, *%_)
  in block <unit> at -e line 1


Also, where is it stated that

   $ p6 '"a b c d e".words(3)[ 2, 4 ].say;'
   (c Nil)

will send the first three words to [2,4] ?

Thank you for helping me with this!

-T

Reply via email to