From wdunlap at tibco.com  Tue May  6 20:39:37 2014
From: wdunlap at tibco.com (William Dunlap)
Date: Tue, 6 May 2014 11:39:37 -0700
Subject: [Rd] Historical NA question
In-Reply-To: <A6D731E4-840D-461A-B6CE-D44730ED46BB@gmail.com>
References: <CABdHhvFt2n6=ORLBSTYxkA_G+t_d_H=0B1+vhhM_ZFL_Z-RT3g@mail.gmail.com>
	<5366EAC6.9030109@yorku.ca> <53681944.9020606@fhcrc.org>
	<4BBA43DC-39CB-4CCC-9172-E2318459FD77@gmail.com>
	<CABdHhvG+20Cx1ZKqNrK7HHMkiusChJFLiSW+Y_tFWrZMPr8umA@mail.gmail.com>
	<A6D731E4-840D-461A-B6CE-D44730ED46BB@gmail.com>
Message-ID: <CAF8bMcY6qaP=dvz3imur9807XoKT+r2A4=Bcq=8n6QnU=uHjXg@mail.gmail.com>

Here is source code for help(Syntax) from S+, which I think follows
closely the original S help file:
.Ix precedence
The following \f6infix\fP operators are recognized by the parser.
They are listed in decreasing precedence.
In the event of ties, evaluation is from left to right.
.sp
.in +.5i
.nf
.ta 1.5i,3.5iR
`$'     component selection     \fBHIGH\fP
`@'     slot selection
`[ [['  subscripts, elements
`^'     exponentiation
`-'     unary minus
`:'     sequence operator
`%'\f2anything\fP`%'    special operator
`*   /' multiply, divide
`+  - ?'        add, subtract, documentation
`<  >  <=  >='
`  ==  !='      comparison
`!'     not
`&   |  &&  ||' and, or
`\~'    formulas
`<<-'   permanent assignment to working data
`<-' `->' `='   assignment      \fBLOW\fP
.sp
.in -.5i
.fi

All logical operators have lower precedence than any comparison
operator and all comparison operators are lower than any arithmetic
operators.  The former means that '! a >= b' is parsed as !(a>=b) and
not the (!a)>=b that C would make it.  Perhaps the difference arose
because didn't have real boolean variables and S did.

(Also, contrary to the original assertion, '%anything%' is in the
middle of the arithmetic operators, above '*' and below ':'.)
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Tue, May 6, 2014 at 10:01 AM, peter dalgaard <pdalgd at gmail.com> wrote:
>
> On 06 May 2014, at 18:20 , Hadley Wickham <h.wickham at gmail.com> wrote:
>
>>>> BTW, that %in% has precedence over arithmetic operations is surprising,
>>>> error-prone, and doesn't cover any reasonable use case (who needs to
>>>> multiply the logical vector returned by %in% by some value?) but that's
>>>> another story:
>>>
>>> The point here is that the %foo% operators all have the _same_ precedence. In principle, they can be user-coded, and there is no way to express what precedence is desirable. It may turn out slightly weird for %in%, but think of what would happen if %*% had lower precedence than addition.
>>
>> This is getting way off topic, but I find the precedence of ! to be
>> more surprising:
>>
>>> !F + !F
>> [1] FALSE
>>
>> i.e. that's interpreted as !(F + !F) not (!F) + (!F).
>
> Yes, UNOT has lower precedence than arithmetic and comparison ops in gram.y. So
>
>> !2<3
> [1] FALSE
>> !2+2==4
> [1] FALSE
>
> I suspect that that is as old as original sin (i.e., inherited from S). Anyone have the Blue Book to hand to verify? It's easy enough to change, but the sky would likely fall down on our heads if we tried...
>
> Also surprising:
>
>> quote(!2+!2)
> !2 + (!2)
>
> where it is somewhat perplexing what the parentheses are supposed to be good for.
>
>
>>
>> Hadley
>>
>> --
>> http://had.co.nz/
>
> --
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Historical NA question
William Dunlap