>>     On 10/1/18 3:37 PM, Donald Hunter wrote:
    >>      > Methods don't accept [], values that are positional do that.
    >>     Is your distinction that [] is actually a routine in itself
    >>     and not part of the method?  And I am lumping them together?
    On 10/2/18 12:18 AM, Laurent Rosenfeld via perl6-users wrote:
    > Yes, [] acts on the result (a positional, e.g. a list) returned by
    > function or method, it does not act on the function or method itself.

    "acts on the result" is a beautiful way to state it.

Just to be clear, the fact that it acts on the result of a method
or function doesn't mean a method or function or result has to
be involved. Consider:


A variable `@array` may well not be a result of anything.


The thing on the left of a postfix `[...]` may not even do the `Positional`

The postfix `[]` operattor turns into an an `AT-POS` method call if
the thing on the left is a `Positional`. The Positional role defines
an `AT-POS` method. Anything that does the `Positional` role will
work as the left hand side of a postfix `[...]`.

But other types that *don't* do the `Positional` role can still have
an `AT-POS` method and a postfix `[...]` will work with them too.


In particular the built in `Any` has an `AT-POS`.

So you can append a `[...]` to any single thing and it'll work:


The above results in 42.


yields "Index out of range. Is: 1, should be in 0..0"


So, to recap: a postfix `[]` acts on whatever is on its left,
pulling out elements from the thing on its left, treated as
a list like thing, with the elements selected according to
the index(es) inside the brackets.


Reply via email to