You're still assuming they're the "same thing"in some sense.

The type of the () postfix operator says it applies to a function or method
(more specifically, to something that supports the Callable role), thus to
"words" itself.
The type of the [] postfix operator says it applies to something that
supports the Positional role; as "words" produces a Positional, the []
applies to the *result* of words.

"words" itself doesn't see or know about either of them. It is invoked by
the () postfix, and its result is processed by the [] postfix.

Do you really think every function that produces a "list" has built into it
secret knowledge of how you would index a list? They just produce a
"Positional" or "Seq" or "List", etc. and *those* know what to do with [].
The function doesn't even need to say it's doing that; that's to produce
better error messages, not "wire what a list is into me".

On Wed, Sep 26, 2018 at 5:32 PM ToddAndMargo <toddandma...@zoho.com> wrote:

> On 9/26/18 11:42 AM, Larry Wall wrote:
> > On Wed, Sep 26, 2018 at 01:16:26PM -0400, Parrot Raiser wrote:
> > : Would it be correct to say:
> > :  [ ] aka square brackets, always surround the subscript of an array or
> > : list, i.e. here "n: is an integer,  [n] always means the nth item,
> > : while
> > : ( ), round brackets or parentheses, separate and group items to
> > : control processing order, and identify subroutine calls, surrounding
> > : the argument list, if any?
> >
> > I'd say there's a bit of confusion here between different syntactic
> > categories.  Your first definition is assuming only postfix position
> > (making [] a "postcircumfix"), while your second definition includes the
> > use of () in both term position and postfix position.  In term position,
> > yes, parentheses control the processing order and group things, but
> > [] also has a term-position interpretation of its own, which is as an
> > array composer (but not a subscript).  In postfix position, [] is always
> > a subscript as you indicated, but () is only for passing arguments
> > to something (and forcing a function call if that something might be
> > construed as a different keyword without the parens).  Any grouping
> > behavior is incidental to the argument processing, and in fact many
> > constructs you can use in normal grouping parens are illegal in an
> > argument list:
> >
> >      > p6 'say abs(42 or 43)'
> >      ===SORRY!=== Error while compiling -e
> >      Unable to parse expression in argument list; couldn't find final
> ')' (corresponding starter was at line 1)
> >      at -e:1
> >      ------> say abs(42⏏ or 43)
> >
> > but in term position that's fine since the inside is a whole statement:
> >
> >      > p6 'say abs (42 or 43)'
> >      42
> >
> > The latter cannot be taken as a postfix because of the space. (Unless
> > you use Tuxic, which confuses this intentionally. :)
> >
> > The three main syntax categories you have to be able to track (and
> > it's much easier to track in Perl 6 than in Perl 5), are:
> >
> >      1) when you're expecting a term
> >      2) when you're expecting a postfix (or infix if there's no postfix)
> >      3) when you're expecting only an infix
> >
> > The careful distinction of which category the grammar engine is expecting
> > is critical to understanding any version of Perl, whether 5 or 6.
> > You can't adequately describe any random syntax in Perl without first
> > nailing down which of the main grammar rules is going to be parsing it.
> >
> > Well, I've probably said more than enough.  :)
> >
> > Larry
> >
>
> Hi Larry,
>
> Wonderful explanation!  Thank you!
>
> Followup question.  I am confused.  How did they get from
>
>       multi method words(Str:D $input: $limit = Inf --> Positional)
>
> to what goes in the () and what goes in the []?
>
> And why are they using the term "$limit" instead of "$selection"?
>
> Yours in confusion,
> -T
>
>
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Computers are like air conditioners.
> They malfunction when you open windows
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>


-- 
brandon s allbery kf8nh
allber...@gmail.com

Reply via email to