M
Mark Jason Dominus
Is this:
@s = qw(a b);
$z = shift(@s) . shift(@s);
print $z;
guaranteed to print "ab"?
@s = qw(a b);
$z = shift(@s) . shift(@s);
print $z;
guaranteed to print "ab"?
Is this:
@s = qw(a b);
$z = shift(@s) . shift(@s);
print $z;
guaranteed to print "ab"?
Is this:
@s = qw(a b);
$z = shift(@s) . shift(@s);
print $z;
guaranteed to print "ab"?
Abigail said:Eric J. Roode ([email protected]) wrote
~~ (e-mail address removed) (Mark Jason Dominus) wrote in ~~ > Is this:
~~ >
~~ > @s = qw(a b);
~~ > $z = shift(@s) . shift(@s);
~~ > print $z;
~~ >
~~ > guaranteed to print "ab"?
~~ >
~~ Yes. Unlike C, Perl's order-of-evaluation is well-defined.
Where is its order of evaluation documented? Where in the documentation
does it say that:
@a = (3, 4, 5);
$z = shift (@a) + shift (@a) * shift (@a);
print $z;
results in 23 being printed?
Unless I'm missing something in your comment, it seems the
question boils down to "what precedence do subroutine/function
calls have?"
Eric J. Roode ([email protected]) wrote on MMMDCXXXIX
September MCMXCIII in
<URL:~~ -----BEGIN
PGP SIGNED MESSAGE----- ~~ Hash: SHA1
~~
~~ (e-mail address removed) (Mark Jason Dominus) wrote in
~~
~~ > Is this:
~~ >
~~ > @s = qw(a b);
~~ > $z = shift(@s) . shift(@s);
~~ > print $z;
~~ >
~~ > guaranteed to print "ab"?
~~ >
~~
~~ Yes. Unlike C, Perl's order-of-evaluation is well-defined.
Where is its order of evaluation documented? Where in the
documentation does it say that:
@a = (3, 4, 5);
$z = shift (@a) + shift (@a) * shift (@a);
print $z;
results in 23 being printed?
Quite predictable and in keeping with precedence.
I'd like to see the "language spec" (whatever that may be) make a
statement one way or the other.
Making it defined will reduce the scope for optomisations in Ponie.
Making it undefied will break a lot of existing code.
Not an easy choice.
Purl said:Michael P. Broida wrote:
Are you being nice to compensate for your first article
directed at me, being a troll article?
Should you listen to Aunt Sally, as many here need to,
you will discover math is very intuitive.
Some of us learned Aunt Sally's math lessons as children.
Annoys me to read those arguing precedence order needs to
be defined.
If Perl's order of precedence was not well defined, intuitively,
this topic would have come up, many years back.
Eric J. Roode said:No, not really. Precedence is different than order of evaluation. In C,
for example, precedence is well-defined, but order of evaluation is
famously undefined.
I suspect that MJD is asking precisely to bring to the fore the fact
that the "language spec" (whatever that may be) currently doesn't
comment one way or the other.
Where is its order of evaluation documented? Where in the documentation
does it say that:
Ah, I -think- I see what you're saying. Maybe.
<grin>
(context removed by Roode)
(topic is Perl following classic mathematical order of evaluation)
Your comment infers you know of code which proves
Perl's precedence order is not defined.
I always found that just breaking complex expressions down into
simpler expressions will guarantee the order you desire. Yes,
it makes for longer, more wordy, programs, but it will do EXACTLY
what you told it to do, without worrying about the language.
That's NOT to say that the language shouldn't specify and
guarantee some specific order. It's just that you can avoid
any potential ordering problems by making it explicit in the
extreme:
$a = $b + $c;
$a = $a * $z;
$a = $a - $x;
(For something THAT simple, I would keep it one line and use
parens to force the order I want, even if it matches the
language. The difference in the compile step is negligible.)
Mark said:Yes, that's what I would like to know.
Or, if it doesn't say that, I would like to know that it doesn't.
Does anyone have any actual facts?
I wasn't able to find anything about it in the manuals, but the
manuals are pretty badly organized on basic matters like this, so I'm
not sure I was looking in the right places.
Tony said:Precedence tells you how to construct the syntax tree for
e.g.
a + b * c
+
a * a + (b * c)
b c
as opposed to
*
+ c (a + b) * c
a b
Order of evaluation OTOH tells you in e.g. from the 2nd
interpretation:
a + b
whether "a" or "b" will be evaluated first (e.g. "a" may
contain a side-effect that touches "b") which is partly a
tree-walking consideration. We still know that (a + b)
will be evaluated in toto before the multiplication.
(Probably hideously over-simplified, compiler-writers take
pity on me![]()
Yes I know. What I was trying to say is that the concatenation
operator is left associative so that:
shift(@a) . shift(@b) . shift(@c) . shift(@d)
will be always be evaluated as:
( ( shift(@a) . shift(@b) ) . shift(@c) ) . shift(@d)
Mark Jason Dominus said:Yes, that's what I would like to know.
Or, if it doesn't say that, I would like to know that it doesn't.
Does anyone have any actual facts?
I wasn't able to find anything about it in the manuals, but the
manuals are pretty badly organized on basic matters like this, so I'm
not sure I was looking in the right places.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.