On 9/26/18 6:04 AM, Brian Duggan wrote:
On Tuesday, September 25, Todd Chester wrote:
Not to ask too obvious a question, but why does words use a []
instead of a () ?
...
I am confused as to when to use [] and when to use () with a method.
If a method is called without arguments, the () can be omitted.
"a man a plan a canal -- panama".words()
"a man a plan a canal -- panama".words # <-- same thing
[] acts on the return value -- it takes an element of a list
"a man a plan a canal -- panama".words()[3]
"a man a plan a canal -- panama".words[3] # <-- same thing
Brian
Hi Brian,
That was beautifully written. Thank you!
I think I did not make myself clear. I know how
to use the function and use it all the time.
My frustration is with
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 []?
My specific goal is to understand what the documentation is trying
to say. That way, instead of grumbling about how bad it is, I can
make some constructive comments to help improve it.
-T