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

Reply via email to