A
Anno Siegel
Abigail said:Anno Siegel ([email protected]) wrote on MMMDCLVI
September MCMXCIII in <URL:!! > In article <[email protected]>,
!! > >Where is its order of evaluation documented? Where in the documentation
!! > >does it say that:
!! >
!! > 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.
!!
!! Like you, I was never able to find a general commitment in the docs.
!! While Perl documentation is huge, and a moving target, I think it's
!! safe to say that it is silent about the point. I mean, *someone*
!! would have found it by now
!!
!! Only some (few) operators are described individually as having left-right
!! evaluation order. Some that come to mind are the short-circuiting boolean
!! operators, the list- and comma operators (both ","), and (I think)
!! assignment ("="), though I'm not entirely sure of the latter.
Where in the documentation do you read that about comma in list context?
Perlop says:
Comma Operator
Binary "," is the comma operator. In scalar context it
evaluates its left argument, throws that value away, then
evaluates its right argument and returns that value. This
is just like C's comma operator.
In list context, it's just the list argument separator,
and inserts both its arguments into the list.
which is explicite for the scalar case, but doesn't say anything about
evaluation order in list context.
Hmm... Your quote above is what I had in mind, but it doesn't say what
I thought it says about the comma as list separator.
Looking for other evidence, I found (in the Camel, p. 109)
Once a list operator starts chewing up comma-separated arguments,
the only things that will stop it are tokens...
which seems to imply a left-to-right progress, but that's about parsing,
not evaluation order. Also, the part has been reworded in the current
perldoc to avoid exactly the left-to-right suggestion. It now talks of
"all comma-separated expressions found there (the right side of a list
operator)".
Elsewhere in the same manual page,
it is written:
In the absence of parentheses, the precedence of list
operators such as "print", "sort", or "chmod" is either
very high or very low depending on whether you are looking
at the left side or the right side of the operator. For
example, in
@ary = (1, 3, sort 4, 2);
print @ary; # prints 1324
the commas on the right of the sort are evaluated before
the sort, but the commas on the left are evaluated after.
which suggest that if there's an evaluation order, it's from right
to left!
I don't understand the argument in this bit of documentation. It would
print "1234", no matter in which order the three list elements are evaluated.
But I can't be bothered now. I must mourn for my lost belief in left-to-
right evaluation of (argument-)lists.
Anno