Skip to content
Prev 33899 / 398503 Next

combining mathematical notation and value substitution

On Thu, 26 Jun 2003, Faheem Mitha wrote:

            
Yes, but Carroll gets that slightly wrong: the song is not "A-sitting On a
Gate", (which is an English phrase, not a song).
The rules are defined by the R grammar, which can be found in
src/main/gram.y (if you speak bison)

Basically, == has lower precedence than *, so one of the == must be the
last function called.  This is necessarily part of the language
definition, as it tells you the meaning of eg
  2*3==6
Since * has higher precedence this is parsed as (2*3)==6, not 2*(3==6).

It doesn't actually matter which == comes first, but we can see from other
examples that the rightmost operator ends up at the root of the tree
Since
[1] TRUE
it must have been evaluated as (2<3)<4,  not 2<(3<4)



While the rules for constructing the tree are part of the language
definition, the order of evaluation might not be.  In C, for example, the
order of evaluation is not specified except to the extent that precedence
constrains it (and for a few special operators like && and ||).

FOr an R example, if you do
	f(plot(a), plot(b))

it is clear that the plot commands must be evaluated before f() returns if
their return values are actually used. It is not clear which order the
plots() appear, and I would say that it shouldn't be part of the language
definition.


	-thomas