Larry Wall wrote:
>  Now, I think I know how to make the parser use precedence on either
>  a prefix or a postfix to get the desired effect (but perhaps not going
>  both directions simulatenously).  But that leads me to a slightly
>  different parsing question, which comes from the asymmetry of postfix
>  operators.  If we make postfix:<!> do the precedence trick above with
>  respect to infix:<**> in order to emulate the superscript notation,
>  then the next question is, are these equivalent:
>     1 + a(x)**2!
>     1 + a(x)**2.!

To me, both of these should raise a(x) to the 2-factorial power; so
yes, they should be equivalent.

>  likewise, should these be parsed the same?
>     $a**2i
>     $a**2.i

In terms of form, or function?  Aesthetically, my gut reaction is to
see these parse the same way, as "raise $a to the power of 2i"; in
practice, though, "2i" on a chalkboard means "2 times i", where "i" is
unitary.  Hmm...

Again, though, this isn't a particularly fair example, as mathematical
notation generally uses superscripting rather than "**" to denote
exponents, allowing the presence or absence of superscripting on the
"i" to determine when it gets evaluated.  That is, the mathematical
notation for exponents includes an implicit grouping mechanism.

>  and if so, how to we rationalize a class of postfix operators that
>  *look* like ordinary method calls but don't parse the same.  In the
>  limit, suppose some defines a postfix "say" looser than comma:
>     (1,2,3)say
>     1,2,3say
>     1,2,3.say
>  Would those all do the same thing?

Gut reaction: the first applies "say" to the list "1, 2, 3"; the
second and third apply "say" to 3.

>  Or should we maybe split postfix
>  dot notation into two different characters depending on whether
>  we mean normal method call or a postfix operator that needs to be
>  syntactically distinguished because we can't write $a.i as $ai?
>  I suppose, if we allow an unspace without any space as a degenerate
>  case, we could write $a\i instead, and it would be equivalent to ($a)i.
>  And it resolves the hypothetical postfix:<say> above:
>     1,2,3.say           # always a method, means 1, 2, (3.say)
>     1,2,3\ say          # the normal unspace, means (1, 2, 3)say
>     1,2,3\say           # degenerate unspace, means (1, 2, 3)say
>  This may also simplify the parsing rules inside double quoted
>  strings if we don't have to figure out whether to include postfix
>  operators like .++ in the interpolation.

I'm in favor of the "minimalist unspace" concept, independent of the
current concerns.  In effect, it lets you insert the equivalent of
whitespace anywhere you want (except in the middle of tokens), even if
whitespace would normally be forbidden; and it does so in a way that
takes up as little space as possible.

>  It does risk a visual
>  clash if someone defines postfix:<t>:
>     $x\t                # means ($x)t
>     "$x\t"              # means $x ~ "\t"
>  I deem that to be an unlikely failure mode, however.

:nod: Alphanumeric postfixes ought to be rare compared to symbolic postfixes.

Jonathan "Dataweaver" Lang

Reply via email to