develooper Front page | perl.perl5.porters | Postings from March 2003

Re: Thought on operator precedence

Thread Previous
From:
Aaron Sherman
Date:
March 13, 2003 10:44
Subject:
Re: Thought on operator precedence
Message ID:
1047581055.12363.516.camel@localhost.localdomain
On Thu, 2003-03-13 at 07:58, Claes Jacobsson wrote:

> according to perlop, concatenation has the same level of precedence as 
> + and -.

Yes, and that's probably the right thing to do.

> $i = 0;
> $v = "foo" . $i + 1;       # feels more natural for "foo1" instead of 
> $v = "foo" . ($i + 1)

I would feel more comfortable *always* using the latter because you have
two very different operations going on there. You have numeric addition
and string concatenation. These are imposing contexts on your values,
and without parens, it can be quite hard to tell where those contexts
are being thrown around without consulting perlop. The current behavior
at least makes the default ordering easy to remember.

This is one of the things that I find makes Perl's contexts difficult to
manage. It's not that applying a context is bad so much as the
application of a context without without some sort of visual context.

In LISP, this would all be non-ambiguous to start (though some rail
against LISP's parentheses, I've yet to see a better way of specifying
expressions in an ambiguity-free way).

Sorry, that was a tangent. I think the bottom-line answer to your query
is that you're more likely to get a precedence change in Perl 6 at this
point than Perl 5.

In Perl 6, the current preliminary parser matches '-', '+' and '_' (Perl
6's string concatenation op) with "$ADDSUB = qr{[-+_]};". I'm a little
out of touch with how that parser works, as I've been off in the guts of
my own Parser for a Perl 5/6 hybrid language I'm writing. However, if
you wanted to suggest the change to the Perl 6 folks, I'm sure you would
at least get more people to consider it than you will here.

> (I would actually like << and >> to be higher than . as well)

	$a << $b . $c

hmm... still sends a chill up my spine without parens.



Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About