From pd@|gd @end|ng |rom gm@||@com  Fri Aug 30 19:45:45 2019
From: pd@|gd @end|ng |rom gm@||@com (peter dalgaard)
Date: Fri, 30 Aug 2019 19:45:45 +0200
Subject: [Rd] ?Syntax wrong about `?`'s precedence ?
In-Reply-To: <CAJXgQP187iVBz79ZJ+_VEGnteTs=WAtqwY=ZPoawLd1enWF+1A@mail.gmail.com>
References: <CAEKh8ugXyz4cmkGrVDc6wxtwR6E9HbEiS3H9qVHzPF7OGyzZ2Q@mail.gmail.com>
 <7d4a921ac2594ecf83944eb594cbfe97@GBDCVPEXC08.corp.lgc-group.com>
 <CAF8bMcYxu+iuKyDZeYbtczimd+1nGBO-VjbTjkv9Va-eBnUhKw@mail.gmail.com>
 <CAJXgQP187iVBz79ZJ+_VEGnteTs=WAtqwY=ZPoawLd1enWF+1A@mail.gmail.com>
Message-ID: <334017CF-CAE8-4270-8A52-BDD8B02C3DB3@gmail.com>

...and 14955, which seems to have the explanation (but was marked as closed/fixed??). The parser does list '?' as lower precedence than '=', but '='-assignments are not normal 'expr's which can appear as arguments to '?'. (Presumably because of named arguments: f(a=b) differs from f(a<-b).)  

Other tokens which have lower precedence than assignments are flow-control items, IF ELSE WHILE FOR REPEAT, but I don't see any way to confuse them in the same way as '?'.

It might be possible to resolve the situation by specifying '?' syntax explicitly as
expr_or_assign '?' expr_or_assign, but, well, "There be Tygers here"...

-pd


> On 30 Aug 2019, at 18:32 , Kevin Ushey <kevinushey at gmail.com> wrote:
> 
> See also: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16710
> 
> On Fri, Aug 30, 2019 at 9:02 AM William Dunlap via R-devel
> <r-devel at r-project.org> wrote:
>> 
>> Precedence is a property of the parser and has nothing to do with the
>> semantics assigned to various symbols.  Using just core R functions you can
>> see the precedence of '?' is between those of '=' and '<-'.
>> 
>>> # '=' has lower precedence than '?'
>>> str(as.list(parse(text="a ? b = c")[[1]]))
>> List of 3
>> $ : symbol =
>> $ : language `?`(a, b)
>> $ : symbol c
>>> str(as.list(parse(text="a = b ? c")[[1]]))
>> List of 3
>> $ : symbol =
>> $ : symbol a
>> $ : language `?`(b, c)
>>> # '<-' has higher precedence than '?'
>>> str(as.list(parse(text="a ? b <- c")[[1]]))
>> List of 3
>> $ : symbol ?
>> $ : symbol a
>> $ : language b <- c
>>> str(as.list(parse(text="a <- b ? c")[[1]]))
>> List of 3
>> $ : symbol ?
>> $ : language a <- b
>> $ : symbol c
>> 
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>> 
>> 
>> On Fri, Aug 30, 2019 at 4:41 AM Stephen Ellison <S.Ellison at lgcgroup.com>
>> wrote:
>> 
>>>> From: R-devel [mailto:r-devel-bounces at r-project.org] On Behalf Of Ant F
>>>> Sent: 29 August 2019 12:06
>>>> To: r-devel at r-project.org
>>>> Subject: [Rd] ?Syntax wrong about `?`'s precedence ?
>>>> ...
>>>> See the following example :
>>>> 
>>>>    `?` <- `+`
>>> 
>>> I'm curious; What did you expect to happen if you replace the function '?'
>>> with the operator '+' ?
>>> ? is surely now being evaluated as a user-defined function and not as an
>>> operator.
>>> Would you expect the results of doing that to be the same as evaluation
>>> without replacement?
>>> 
>>> S Ellison
>>> 
>>> 
>>> 
>>> 
>>> *******************************************************************
>>> This email and any attachments are confidential. Any u...{{dropped:10}}
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] ?Syntax wrong about `?`'s precedence ?
peter dalgaard