develooper Front page | perl.perl5.porters | Postings from July 2010

Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)

Thread Previous | Thread Next
From:
David Golden
Date:
July 15, 2010 09:25
Subject:
Re: Order of evaluation of terms (was peephole optimiser could prune more dead code)
Message ID:
AANLkTil9qEMdoGrwi8DLe3umytZGRahFEzP_kWq9TIP_@mail.gmail.com
On Thu, Jul 15, 2010 at 11:51 AM, Eric Brine <ikegami@adaelis.com> wrote:
> Functions calls are not on the precedence table. They are considered terms
> (not operators) at the grammar level.

From perlop:

   Terms and List Operators (Leftward)
       A TERM has the highest precedence in Perl.  They include variables,
       quote and quote-like operators, any expression in parentheses, and any
       function whose arguments are parenthesized.  Actually, there aren't
       really functions in this sense, just list operators and unary operators
       behaving as functions because you put parentheses around the arguments.
       These are all documented in perlfunc.

Thus it seems clear that functions get evaluated first.

Maybe it's even more direct.  Given:

   f() . g()

The first thing encountered is a "function operation" on f, which must
be evaluated before a concatenation.  Then:

  $result . g()

The function operation on g has higher precedence and is evaluated.
Then the concatenation is evaluated.  This is analogous to:

  1 * 2 + 3 * 4

So, as written, it sounds to me like f() should happen before g().

-- David

Thread Previous | Thread Next


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