Re: precedence (was 'historical NA question')

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Therneau, Terry M., Ph.D.
Hadley asked about the Blue book; my shelf still has the earlier brown book
    Becker and Chambers, 1984, S: An interactive environment for data analysis and graphics.

The manual page for precedence is

$               component select
%x              special operator
-               unary minus
:               sequence operator
^ **            exponentiation
* /             mult/div
+ -             add/sub
< > <= >= == != logical
!               not
& |             and/or
<- ->           assignment

Terry Therneau

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Tierney, Luke
On Wed, 7 May 2014, Therneau, Terry M., Ph.D. wrote:

> Hadley asked about the Blue book; my shelf still has the earlier brown book
>   Becker and Chambers, 1984, S: An interactive environment for data analysis
> and graphics.
>
> The manual page for precedence is
>
> $               component select
> %x              special operator
> -               unary minus
> :               sequence operator
> ^ **            exponentiation
> * /             mult/div
> + -             add/sub
> < > <= >= == != logical
> !               not
> & |             and/or
> <- ->           assignment
>

which did lead to some head scratching after plotting exp(-x^2) :-)

luke

> Terry Therneau
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

John Chambers-2
In reply to this post by Therneau, Terry M., Ph.D.
On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
> Hadley asked about the Blue book; my shelf still has the earlier brown book
>     Becker and Chambers, 1984, S: An interactive environment for data
> analysis and graphics.

Historically interesting, but there was never a guarantee that Version 3
of S (the "blue book") was back-compatible with earlier versions.  We
gave users some help in "getting on the road" to converting, that was
all (see Appendix 4 to the blue book).

For that one brief moment, we felt free to innovate.

John

>
> The manual page for precedence is
>
> $               component select
> %x              special operator
> -               unary minus
> :               sequence operator
> ^ **            exponentiation
> * /             mult/div
> + -             add/sub
> < > <= >= == != logical
> !               not
> & |             and/or
> <- ->           assignment
>
> Terry Therneau
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
No big deal. These things can be tricky:

  https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html

Sorry I couldn't resist ;-)

H.

On 05/07/2014 09:16 AM, John Chambers wrote:

> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>> Hadley asked about the Blue book; my shelf still has the earlier brown
>> book
>>     Becker and Chambers, 1984, S: An interactive environment for data
>> analysis and graphics.
>
> Historically interesting, but there was never a guarantee that Version 3
> of S (the "blue book") was back-compatible with earlier versions.  We
> gave users some help in "getting on the road" to converting, that was
> all (see Appendix 4 to the blue book).
>
> For that one brief moment, we felt free to innovate.
>
> John
>
>>
>> The manual page for precedence is
>>
>> $               component select
>> %x              special operator
>> -               unary minus
>> :               sequence operator
>> ^ **            exponentiation
>> * /             mult/div
>> + -             add/sub
>> < > <= >= == != logical
>> !               not
>> & |             and/or
>> <- ->           assignment
>>
>> Terry Therneau
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Simon Urbanek
On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:

> No big deal. These things can be tricky:
>
> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>
> Sorry I couldn't resist ;-)
>

Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…


> On 05/07/2014 09:16 AM, John Chambers wrote:
>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>> book
>>>    Becker and Chambers, 1984, S: An interactive environment for data
>>> analysis and graphics.
>>
>> Historically interesting, but there was never a guarantee that Version 3
>> of S (the "blue book") was back-compatible with earlier versions.  We
>> gave users some help in "getting on the road" to converting, that was
>> all (see Appendix 4 to the blue book).
>>
>> For that one brief moment, we felt free to innovate.
>>
>> John
>>
>>>
>>> The manual page for precedence is
>>>
>>> $               component select
>>> %x              special operator
>>> -               unary minus
>>> :               sequence operator
>>> ^ **            exponentiation
>>> * /             mult/div
>>> + -             add/sub
>>> < > <= >= == != logical
>>> !               not
>>> & |             and/or
>>> <- ->           assignment
>>>
>>> Terry Therneau
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: [hidden email]
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Peter Dalgaard-2

On 07 May 2014, at 21:52 , Simon Urbanek <[hidden email]> wrote:

> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>
>> No big deal. These things can be tricky:
>>
>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>
>> Sorry I couldn't resist ;-)
>>
>
> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…
>

It's painful, but

> bquote(.(-2)^2)
-2^2
> eval(bquote(.(-2)^2))
[1] 4
> bquote(.(-2)^2)[[2]]
[1] -2
> mode(bquote(.(-2)^2)[[2]])
[1] "numeric"

The difficulty is that the tokenizer, which recognizes language elements before the parser goes to work on the grammatical structure, is unable to distinguish the -2 in "-2 + 2" from the one in "-2 ^ y". And since constants are generated by the tokenizer, negative ones are not generated. I don't think it is completely out of reach for the parser to recognize the pattern "unary minus a numeric constant" and fold it into a constant of the opposite sign, but I'm not volunteering... (and anyways, it is part of the bigger issue of general constant folding --- I suppose that Luke has a handle on that.)


>
>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>> book
>>>>   Becker and Chambers, 1984, S: An interactive environment for data
>>>> analysis and graphics.
>>>
>>> Historically interesting, but there was never a guarantee that Version 3
>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>> gave users some help in "getting on the road" to converting, that was
>>> all (see Appendix 4 to the blue book).
>>>
>>> For that one brief moment, we felt free to innovate.
>>>
>>> John
>>>
>>>>
>>>> The manual page for precedence is
>>>>
>>>> $               component select
>>>> %x              special operator
>>>> -               unary minus
>>>> :               sequence operator
>>>> ^ **            exponentiation
>>>> * /             mult/div
>>>> + -             add/sub
>>>> < > <= >= == != logical
>>>> !               not
>>>> & |             and/or
>>>> <- ->           assignment
>>>>
>>>> Terry Therneau
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> [hidden email] 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
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
In reply to this post by Simon Urbanek
On 05/07/2014 12:52 PM, Simon Urbanek wrote:

> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>
>> No big deal. These things can be tricky:
>>
>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>
>> Sorry I couldn't resist ;-)
>>
>
> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant?

You wouldn't want -2 to be parsed as a single constant exactly for
the reason that you wouldn't want -2^2 to return 4. Having -2^2 treated
the same way as -x^2 is a sane feature.

> Is there a way to express a negative constant in R? Hmm…

Maybe some people have some use cases for this (speed ?).
Personally I don't. Of course it would require a special syntax,
something that would probably be as ugly and confusing as the
L suffix used for integer constants (L means long int in C).

H.

>
>
>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>> book
>>>>     Becker and Chambers, 1984, S: An interactive environment for data
>>>> analysis and graphics.
>>>
>>> Historically interesting, but there was never a guarantee that Version 3
>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>> gave users some help in "getting on the road" to converting, that was
>>> all (see Appendix 4 to the blue book).
>>>
>>> For that one brief moment, we felt free to innovate.
>>>
>>> John
>>>
>>>>
>>>> The manual page for precedence is
>>>>
>>>> $               component select
>>>> %x              special operator
>>>> -               unary minus
>>>> :               sequence operator
>>>> ^ **            exponentiation
>>>> * /             mult/div
>>>> + -             add/sub
>>>> < > <= >= == != logical
>>>> !               not
>>>> & |             and/or
>>>> <- ->           assignment
>>>>
>>>> Terry Therneau
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
In reply to this post by Peter Dalgaard-2
On 05/07/2014 02:01 PM, peter dalgaard wrote:

>
> On 07 May 2014, at 21:52 , Simon Urbanek <[hidden email]> wrote:
>
>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>
>>> No big deal. These things can be tricky:
>>>
>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>
>>> Sorry I couldn't resist ;-)
>>>
>>
>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…
>>
>
> It's painful, but
>
>> bquote(.(-2)^2)
> -2^2
>> eval(bquote(.(-2)^2))
> [1] 4
>> bquote(.(-2)^2)[[2]]
> [1] -2
>> mode(bquote(.(-2)^2)[[2]])
> [1] "numeric"
>
> The difficulty is that the tokenizer, which recognizes language elements before the parser goes to work on the grammatical structure, is unable to distinguish the -2 in "-2 + 2" from the one in "-2 ^ y".

Are you saying that the tokenizer could be made smarter and recognize
"-2" as a token in "-2 ^ y", just because you didn't put a space between
"-" and "2"? So in "-2 ^ y" it would be token, but not in "- 2^y".
An therefore precedence would now depend on whether there is a space
after the minus or not, or something like that? I'm confused.

H.

> And since constants are generated by the tokenizer, negative ones are not generated. I don't think it is completely out of reach for the parser to recognize the pattern "unary minus a numeric constant" and fold it into a constant of the opposite sign, but I'm not volunteering... (and anyways, it is part of the bigger issue of general constant folding --- I suppose that Luke has a handle on that.)
>
>
>>
>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>> book
>>>>>    Becker and Chambers, 1984, S: An interactive environment for data
>>>>> analysis and graphics.
>>>>
>>>> Historically interesting, but there was never a guarantee that Version 3
>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>> gave users some help in "getting on the road" to converting, that was
>>>> all (see Appendix 4 to the blue book).
>>>>
>>>> For that one brief moment, we felt free to innovate.
>>>>
>>>> John
>>>>
>>>>>
>>>>> The manual page for precedence is
>>>>>
>>>>> $               component select
>>>>> %x              special operator
>>>>> -               unary minus
>>>>> :               sequence operator
>>>>> ^ **            exponentiation
>>>>> * /             mult/div
>>>>> + -             add/sub
>>>>> < > <= >= == != logical
>>>>> !               not
>>>>> & |             and/or
>>>>> <- ->           assignment
>>>>>
>>>>> Terry Therneau
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>> --
>>> Hervé Pagès
>>>
>>> Program in Computational Biology
>>> Division of Public Health Sciences
>>> Fred Hutchinson Cancer Research Center
>>> 1100 Fairview Ave. N, M1-B514
>>> P.O. Box 19024
>>> Seattle, WA 98109-1024
>>>
>>> E-mail: [hidden email]
>>> Phone:  (206) 667-5791
>>> Fax:    (206) 667-1319
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Simon Urbanek
In reply to this post by Hervé Pagès

On May 7, 2014, at 5:17 PM, Hervé Pagès <[hidden email]> wrote:

> On 05/07/2014 12:52 PM, Simon Urbanek wrote:
>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>
>>> No big deal. These things can be tricky:
>>>
>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>
>>> Sorry I couldn't resist ;-)
>>>
>>
>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant?
>
> You wouldn't want -2 to be parsed as a single constant exactly for
> the reason that you wouldn't want -2^2 to return 4. Having -2^2 treated
> the same way as -x^2 is a sane feature.
>

On what grounds? -2 is one value - negative two - and if you square it, you get four - so that's not even a question of precedence. It's just a matter of interpretation: do you see the constant -2 or do you see the constant 2 with unary minus? When you print -2 you get -2 - and that's not a positive constant with an unary minus - or is it? ;) - aaah, will we ever know … R is good at hiding that subtlety from us:

> a = quote(-2^2)
> b = bquote(.(-2)^2)
> a
-2^2
> b
-2^2
> eval(a)
[1] -4
> eval(b)
[1] 4


>> Is there a way to express a negative constant in R? Hmm…
>
> Maybe some people have some use cases for this (speed ?).

Wrong tree ;). You kick-started the trip but failed to follow the path it takes into the depths of the human mind … :P (or was that computer mind? ;))

Cheers,
Simon



> Personally I don't. Of course it would require a special syntax,
> something that would probably be as ugly and confusing as the
> L suffix used for integer constants (L means long int in C).
>
> H.
>
>>
>>
>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>> book
>>>>>    Becker and Chambers, 1984, S: An interactive environment for data
>>>>> analysis and graphics.
>>>>
>>>> Historically interesting, but there was never a guarantee that Version 3
>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>> gave users some help in "getting on the road" to converting, that was
>>>> all (see Appendix 4 to the blue book).
>>>>
>>>> For that one brief moment, we felt free to innovate.
>>>>
>>>> John
>>>>
>>>>>
>>>>> The manual page for precedence is
>>>>>
>>>>> $               component select
>>>>> %x              special operator
>>>>> -               unary minus
>>>>> :               sequence operator
>>>>> ^ **            exponentiation
>>>>> * /             mult/div
>>>>> + -             add/sub
>>>>> < > <= >= == != logical
>>>>> !               not
>>>>> & |             and/or
>>>>> <- ->           assignment
>>>>>
>>>>> Terry Therneau
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>> --
>>> Hervé Pagès
>>>
>>> Program in Computational Biology
>>> Division of Public Health Sciences
>>> Fred Hutchinson Cancer Research Center
>>> 1100 Fairview Ave. N, M1-B514
>>> P.O. Box 19024
>>> Seattle, WA 98109-1024
>>>
>>> E-mail: [hidden email]
>>> Phone:  (206) 667-5791
>>> Fax:    (206) 667-1319
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: [hidden email]
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Simon Urbanek
In reply to this post by Hervé Pagès

On May 7, 2014, at 5:41 PM, Hervé Pagès <[hidden email]> wrote:

> On 05/07/2014 02:01 PM, peter dalgaard wrote:
>>
>> On 07 May 2014, at 21:52 , Simon Urbanek <[hidden email]> wrote:
>>
>>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>>
>>>> No big deal. These things can be tricky:
>>>>
>>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>>
>>>> Sorry I couldn't resist ;-)
>>>>
>>>
>>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…
>>>
>>
>> It's painful, but
>>
>>> bquote(.(-2)^2)
>> -2^2
>>> eval(bquote(.(-2)^2))
>> [1] 4
>>> bquote(.(-2)^2)[[2]]
>> [1] -2
>>> mode(bquote(.(-2)^2)[[2]])
>> [1] "numeric"
>>
>> The difficulty is that the tokenizer, which recognizes language elements before the parser goes to work on the grammatical structure, is unable to distinguish the -2 in "-2 + 2" from the one in "-2 ^ y".
>
> Are you saying that the tokenizer could be made smarter and recognize
> "-2" as a token in "-2 ^ y", just because you didn't put a space between
> "-" and "2"? So in "-2 ^ y" it would be token, but not in "- 2^y".
> An therefore precedence would now depend on whether there is a space
> after the minus or not, or something like that? I'm confused.
>

Nope, precedence would not change at all. "-2" and "- 2" are two different things - in case you didn't realize that spaces are important, try "a<-2" vs "a< -2". So, again, if -2 is a value then there is no precedence issue, since you have only operator in  "-2 ^ y" namely "^". In "- 2 ^ y" you have two operators, so precedence matters.

Cheers,
Simon



> H.
>
>> And since constants are generated by the tokenizer, negative ones are not generated. I don't think it is completely out of reach for the parser to recognize the pattern "unary minus a numeric constant" and fold it into a constant of the opposite sign, but I'm not volunteering... (and anyways, it is part of the bigger issue of general constant folding --- I suppose that Luke has a handle on that.)
>>
>>
>>>
>>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>>> book
>>>>>>   Becker and Chambers, 1984, S: An interactive environment for data
>>>>>> analysis and graphics.
>>>>>
>>>>> Historically interesting, but there was never a guarantee that Version 3
>>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>>> gave users some help in "getting on the road" to converting, that was
>>>>> all (see Appendix 4 to the blue book).
>>>>>
>>>>> For that one brief moment, we felt free to innovate.
>>>>>
>>>>> John
>>>>>
>>>>>>
>>>>>> The manual page for precedence is
>>>>>>
>>>>>> $               component select
>>>>>> %x              special operator
>>>>>> -               unary minus
>>>>>> :               sequence operator
>>>>>> ^ **            exponentiation
>>>>>> * /             mult/div
>>>>>> + -             add/sub
>>>>>> < > <= >= == != logical
>>>>>> !               not
>>>>>> & |             and/or
>>>>>> <- ->           assignment
>>>>>>
>>>>>> Terry Therneau
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>> --
>>>> Hervé Pagès
>>>>
>>>> Program in Computational Biology
>>>> Division of Public Health Sciences
>>>> Fred Hutchinson Cancer Research Center
>>>> 1100 Fairview Ave. N, M1-B514
>>>> P.O. Box 19024
>>>> Seattle, WA 98109-1024
>>>>
>>>> E-mail: [hidden email]
>>>> Phone:  (206) 667-5791
>>>> Fax:    (206) 667-1319
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: [hidden email]
> Phone:  (206) 667-5791
> Fax:    (206) 667-1319
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Duncan Murdoch-2
On 07/05/2014, 5:55 PM, Simon Urbanek wrote:

>
> On May 7, 2014, at 5:41 PM, Hervé Pagès <[hidden email]> wrote:
>
>> On 05/07/2014 02:01 PM, peter dalgaard wrote:
>>>
>>> On 07 May 2014, at 21:52 , Simon Urbanek <[hidden email]> wrote:
>>>
>>>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>>>
>>>>> No big deal. These things can be tricky:
>>>>>
>>>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>>>
>>>>> Sorry I couldn't resist ;-)
>>>>>
>>>>
>>>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…
>>>>
>>>
>>> It's painful, but
>>>
>>>> bquote(.(-2)^2)
>>> -2^2
>>>> eval(bquote(.(-2)^2))
>>> [1] 4
>>>> bquote(.(-2)^2)[[2]]
>>> [1] -2
>>>> mode(bquote(.(-2)^2)[[2]])
>>> [1] "numeric"
>>>
>>> The difficulty is that the tokenizer, which recognizes language elements before the parser goes to work on the grammatical structure, is unable to distinguish the -2 in "-2 + 2" from the one in "-2 ^ y".
>>
>> Are you saying that the tokenizer could be made smarter and recognize
>> "-2" as a token in "-2 ^ y", just because you didn't put a space between
>> "-" and "2"? So in "-2 ^ y" it would be token, but not in "- 2^y".
>> An therefore precedence would now depend on whether there is a space
>> after the minus or not, or something like that? I'm confused.
>>
>
> Nope, precedence would not change at all. "-2" and "- 2" are two different things - in case you didn't realize that spaces are important, try "a<-2" vs "a< -2". So, again, if -2 is a value then there is no precedence issue, since you have only operator in  "-2 ^ y" namely "^". In "- 2 ^ y" you have two operators, so precedence matters.

Is there a language where "- 2^2" gives a different answer than "-2^2"?
  (Substitute ** or any other exponentiation operator for ^ if you
like.)  This is important, because I'd like to avoid ever attempting any
important calculation in that language.

Duncan Murdoch

> Cheers,
> Simon
>
>
>
>> H.
>>
>>> And since constants are generated by the tokenizer, negative ones are not generated. I don't think it is completely out of reach for the parser to recognize the pattern "unary minus a numeric constant" and fold it into a constant of the opposite sign, but I'm not volunteering... (and anyways, it is part of the bigger issue of general constant folding --- I suppose that Luke has a handle on that.)
>>>
>>>
>>>>
>>>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>>>> book
>>>>>>>    Becker and Chambers, 1984, S: An interactive environment for data
>>>>>>> analysis and graphics.
>>>>>>
>>>>>> Historically interesting, but there was never a guarantee that Version 3
>>>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>>>> gave users some help in "getting on the road" to converting, that was
>>>>>> all (see Appendix 4 to the blue book).
>>>>>>
>>>>>> For that one brief moment, we felt free to innovate.
>>>>>>
>>>>>> John
>>>>>>
>>>>>>>
>>>>>>> The manual page for precedence is
>>>>>>>
>>>>>>> $               component select
>>>>>>> %x              special operator
>>>>>>> -               unary minus
>>>>>>> :               sequence operator
>>>>>>> ^ **            exponentiation
>>>>>>> * /             mult/div
>>>>>>> + -             add/sub
>>>>>>> < > <= >= == != logical
>>>>>>> !               not
>>>>>>> & |             and/or
>>>>>>> <- ->           assignment
>>>>>>>
>>>>>>> Terry Therneau
>>>>>>>
>>>>>>> ______________________________________________
>>>>>>> [hidden email] mailing list
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>> --
>>>>> Hervé Pagès
>>>>>
>>>>> Program in Computational Biology
>>>>> Division of Public Health Sciences
>>>>> Fred Hutchinson Cancer Research Center
>>>>> 1100 Fairview Ave. N, M1-B514
>>>>> P.O. Box 19024
>>>>> Seattle, WA 98109-1024
>>>>>
>>>>> E-mail: [hidden email]
>>>>> Phone:  (206) 667-5791
>>>>> Fax:    (206) 667-1319
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
In reply to this post by Simon Urbanek


On 05/07/2014 02:55 PM, Simon Urbanek wrote:

>
> On May 7, 2014, at 5:41 PM, Hervé Pagès <[hidden email]> wrote:
>
>> On 05/07/2014 02:01 PM, peter dalgaard wrote:
>>>
>>> On 07 May 2014, at 21:52 , Simon Urbanek <[hidden email]> wrote:
>>>
>>>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>>>
>>>>> No big deal. These things can be tricky:
>>>>>
>>>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>>>
>>>>> Sorry I couldn't resist ;-)
>>>>>
>>>>
>>>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant? Is there a way to express a negative constant in R? Hmm…
>>>>
>>>
>>> It's painful, but
>>>
>>>> bquote(.(-2)^2)
>>> -2^2
>>>> eval(bquote(.(-2)^2))
>>> [1] 4
>>>> bquote(.(-2)^2)[[2]]
>>> [1] -2
>>>> mode(bquote(.(-2)^2)[[2]])
>>> [1] "numeric"
>>>
>>> The difficulty is that the tokenizer, which recognizes language elements before the parser goes to work on the grammatical structure, is unable to distinguish the -2 in "-2 + 2" from the one in "-2 ^ y".
>>
>> Are you saying that the tokenizer could be made smarter and recognize
>> "-2" as a token in "-2 ^ y", just because you didn't put a space between
>> "-" and "2"? So in "-2 ^ y" it would be token, but not in "- 2^y".
>> An therefore precedence would now depend on whether there is a space
>> after the minus or not, or something like that? I'm confused.
>>
>
> Nope, precedence would not change at all. "-2" and "- 2" are two different things - in case you didn't realize that spaces are important, try "a<-2" vs "a< -2".

Yes, there is an precedent where space matters. I just hope you're not
saying you'd like to see that repeated for "-2" vs "- 2".

> So, again, if -2 is a value then there is no precedence issue, since you have only operator in  "-2 ^ y" namely "^".

If you make -2 a value, then yes you *effectively* change precedence
from a user point of view. You can be picky about terminology and argue
that it's not an "operator precedence" issue because there is no
operator involved but that doesn't change the fact that now it's a very
bad idea. I can't believe serious programmers are discussing ways to
make -2^2 return 4.

H.

> In "- 2 ^ y" you have two operators, so precedence matters.
>
> Cheers,
> Simon
>
>
>
>> H.
>>
>>> And since constants are generated by the tokenizer, negative ones are not generated. I don't think it is completely out of reach for the parser to recognize the pattern "unary minus a numeric constant" and fold it into a constant of the opposite sign, but I'm not volunteering... (and anyways, it is part of the bigger issue of general constant folding --- I suppose that Luke has a handle on that.)
>>>
>>>
>>>>
>>>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>>>> book
>>>>>>>    Becker and Chambers, 1984, S: An interactive environment for data
>>>>>>> analysis and graphics.
>>>>>>
>>>>>> Historically interesting, but there was never a guarantee that Version 3
>>>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>>>> gave users some help in "getting on the road" to converting, that was
>>>>>> all (see Appendix 4 to the blue book).
>>>>>>
>>>>>> For that one brief moment, we felt free to innovate.
>>>>>>
>>>>>> John
>>>>>>
>>>>>>>
>>>>>>> The manual page for precedence is
>>>>>>>
>>>>>>> $               component select
>>>>>>> %x              special operator
>>>>>>> -               unary minus
>>>>>>> :               sequence operator
>>>>>>> ^ **            exponentiation
>>>>>>> * /             mult/div
>>>>>>> + -             add/sub
>>>>>>> < > <= >= == != logical
>>>>>>> !               not
>>>>>>> & |             and/or
>>>>>>> <- ->           assignment
>>>>>>>
>>>>>>> Terry Therneau
>>>>>>>
>>>>>>> ______________________________________________
>>>>>>> [hidden email] mailing list
>>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>> --
>>>>> Hervé Pagès
>>>>>
>>>>> Program in Computational Biology
>>>>> Division of Public Health Sciences
>>>>> Fred Hutchinson Cancer Research Center
>>>>> 1100 Fairview Ave. N, M1-B514
>>>>> P.O. Box 19024
>>>>> Seattle, WA 98109-1024
>>>>>
>>>>> E-mail: [hidden email]
>>>>> Phone:  (206) 667-5791
>>>>> Fax:    (206) 667-1319
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
In reply to this post by Simon Urbanek
On 05/07/2014 02:45 PM, Simon Urbanek wrote:

>
> On May 7, 2014, at 5:17 PM, Hervé Pagès <[hidden email]> wrote:
>
>> On 05/07/2014 12:52 PM, Simon Urbanek wrote:
>>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>>
>>>> No big deal. These things can be tricky:
>>>>
>>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>>
>>>> Sorry I couldn't resist ;-)
>>>>
>>>
>>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant?
>>
>> You wouldn't want -2 to be parsed as a single constant exactly for
>> the reason that you wouldn't want -2^2 to return 4. Having -2^2 treated
>> the same way as -x^2 is a sane feature.
>>
>
> On what grounds?

The last few centuries of mathematics. Some clever people have been
thinking about defining the rules for writing concise algebraic
expressions that do not leave room for interpretation/ambiguities.

> -2 is one value - negative two - and if you square it, you get four - so that's not even a question of precedence. It's just a matter of interpretation: do you see the constant -2 or do you see the constant 2 with unary minus?

In -2^2, there is no question I see the latter. I'm a little biased
though, because, you know, I have some respect and admiration for the
tradition.

H.

> When you print -2 you get -2 - and that's not a positive constant with an unary minus - or is it? ;) - aaah, will we ever know … R is good at hiding that subtlety from us:
>
>> a = quote(-2^2)
>> b = bquote(.(-2)^2)
>> a
> -2^2
>> b
> -2^2
>> eval(a)
> [1] -4
>> eval(b)
> [1] 4
>
>
>>> Is there a way to express a negative constant in R? Hmm…
>>
>> Maybe some people have some use cases for this (speed ?).
>
> Wrong tree ;). You kick-started the trip but failed to follow the path it takes into the depths of the human mind … :P (or was that computer mind? ;))
>
> Cheers,
> Simon
>
>
>
>> Personally I don't. Of course it would require a special syntax,
>> something that would probably be as ugly and confusing as the
>> L suffix used for integer constants (L means long int in C).
>>
>> H.
>>
>>>
>>>
>>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>>> book
>>>>>>     Becker and Chambers, 1984, S: An interactive environment for data
>>>>>> analysis and graphics.
>>>>>
>>>>> Historically interesting, but there was never a guarantee that Version 3
>>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>>> gave users some help in "getting on the road" to converting, that was
>>>>> all (see Appendix 4 to the blue book).
>>>>>
>>>>> For that one brief moment, we felt free to innovate.
>>>>>
>>>>> John
>>>>>
>>>>>>
>>>>>> The manual page for precedence is
>>>>>>
>>>>>> $               component select
>>>>>> %x              special operator
>>>>>> -               unary minus
>>>>>> :               sequence operator
>>>>>> ^ **            exponentiation
>>>>>> * /             mult/div
>>>>>> + -             add/sub
>>>>>> < > <= >= == != logical
>>>>>> !               not
>>>>>> & |             and/or
>>>>>> <- ->           assignment
>>>>>>
>>>>>> Terry Therneau
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>> --
>>>> Hervé Pagès
>>>>
>>>> Program in Computational Biology
>>>> Division of Public Health Sciences
>>>> Fred Hutchinson Cancer Research Center
>>>> 1100 Fairview Ave. N, M1-B514
>>>> P.O. Box 19024
>>>> Seattle, WA 98109-1024
>>>>
>>>> E-mail: [hidden email]
>>>> Phone:  (206) 667-5791
>>>> Fax:    (206) 667-1319
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Hervé Pagès
In reply to this post by Simon Urbanek


On 05/07/2014 02:45 PM, Simon Urbanek wrote:

>
> On May 7, 2014, at 5:17 PM, Hervé Pagès <[hidden email]> wrote:
>
>> On 05/07/2014 12:52 PM, Simon Urbanek wrote:
>>> On May 7, 2014, at 3:37 PM, Hervé Pagès <[hidden email]> wrote:
>>>
>>>> No big deal. These things can be tricky:
>>>>
>>>> https://stat.ethz.ch/pipermail/r-devel/2006-January/036022.html
>>>>
>>>> Sorry I couldn't resist ;-)
>>>>
>>>
>>> Yeah, but that's just yet another trip down the rabbit hole - why is -2 parsed as `-`(2) and not a single constant?
>>
>> You wouldn't want -2 to be parsed as a single constant exactly for
>> the reason that you wouldn't want -2^2 to return 4. Having -2^2 treated
>> the same way as -x^2 is a sane feature.
>>
>
> On what grounds? -2 is one value - negative two - and if you square it, you get four - so that's not even a question of precedence. It's just a matter of interpretation: do you see the constant -2 or do you see the constant 2 with unary minus? When you print -2 you get -2 - and that's not a positive constant with an unary minus - or is it? ;) - aaah, will we ever know … R is good at hiding that subtlety from us:
>
>> a = quote(-2^2)
>> b = bquote(.(-2)^2)
>> a
> -2^2
>> b
> -2^2
>> eval(a)
> [1] -4
>> eval(b)
> [1] 4
>
>
>>> Is there a way to express a negative constant in R? Hmm…
>>
>> Maybe some people have some use cases for this (speed ?).
>
> Wrong tree ;). You kick-started the trip but failed to follow the path it takes into the depths of the human mind … :P (or was that computer mind? ;))

BTW I don't see anything deep here, except maybe for the rabbit hole
you've put yourself in. Just sayin'...

H.

>
> Cheers,
> Simon
>
>
>
>> Personally I don't. Of course it would require a special syntax,
>> something that would probably be as ugly and confusing as the
>> L suffix used for integer constants (L means long int in C).
>>
>> H.
>>
>>>
>>>
>>>> On 05/07/2014 09:16 AM, John Chambers wrote:
>>>>> On 5/7/14, 5:21 AM, Therneau, Terry M., Ph.D. wrote:
>>>>>> Hadley asked about the Blue book; my shelf still has the earlier brown
>>>>>> book
>>>>>>     Becker and Chambers, 1984, S: An interactive environment for data
>>>>>> analysis and graphics.
>>>>>
>>>>> Historically interesting, but there was never a guarantee that Version 3
>>>>> of S (the "blue book") was back-compatible with earlier versions.  We
>>>>> gave users some help in "getting on the road" to converting, that was
>>>>> all (see Appendix 4 to the blue book).
>>>>>
>>>>> For that one brief moment, we felt free to innovate.
>>>>>
>>>>> John
>>>>>
>>>>>>
>>>>>> The manual page for precedence is
>>>>>>
>>>>>> $               component select
>>>>>> %x              special operator
>>>>>> -               unary minus
>>>>>> :               sequence operator
>>>>>> ^ **            exponentiation
>>>>>> * /             mult/div
>>>>>> + -             add/sub
>>>>>> < > <= >= == != logical
>>>>>> !               not
>>>>>> & |             and/or
>>>>>> <- ->           assignment
>>>>>>
>>>>>> Terry Therneau
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] mailing list
>>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>> --
>>>> Hervé Pagès
>>>>
>>>> Program in Computational Biology
>>>> Division of Public Health Sciences
>>>> Fred Hutchinson Cancer Research Center
>>>> 1100 Fairview Ave. N, M1-B514
>>>> P.O. Box 19024
>>>> Seattle, WA 98109-1024
>>>>
>>>> E-mail: [hidden email]
>>>> Phone:  (206) 667-5791
>>>> Fax:    (206) 667-1319
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>
>> --
>> Hervé Pagès
>>
>> Program in Computational Biology
>> Division of Public Health Sciences
>> Fred Hutchinson Cancer Research Center
>> 1100 Fairview Ave. N, M1-B514
>> P.O. Box 19024
>> Seattle, WA 98109-1024
>>
>> E-mail: [hidden email]
>> Phone:  (206) 667-5791
>> Fax:    (206) 667-1319
>>
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

barry rowlingson
In reply to this post by Simon Urbanek
On Wed, May 7, 2014 at 11:00 PM, Duncan Murdoch
<[hidden email]> wrote:
>
>
> Is there a language where "- 2^2" gives a different answer than "-2^2"?
>   (Substitute ** or any other exponentiation operator for ^ if you
> like.)  This is important, because I'd like to avoid ever attempting any
> important calculation in that language.
>

I just checked that with javascript, and it gives the same answer so
that's okay. I tried JS because it has some fun things to do with
numbers (especially if you let it coerce strings):

 > "2" - "1"
1
 > "2" + "1"
"21"

The Javascript Best Practices Document[1] says you should never use
the plus sign for arithmetic addition, instead use a double negative
and rely on "subtract" converting to numeric:

 > "2"- -"1"
 3

Given that web pages written with JS get all their data from web
content as strings, this can happen more often than you think.

This is an example to show to everyone who says "Can we use + to
concatenate strings in R please!?".

Barry

[1] A completely fictional publication I invented just now, but hey,
I've seen worse than this.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: precedence (was 'historical NA question')

Gábor Csárdi
On Thu, May 8, 2014 at 3:35 AM, Barry Rowlingson <
[hidden email]> wrote:
[...]

This is an example to show to everyone who says "Can we use + to
> concatenate strings in R please!?".
>

This is one of my main complaints against the R syntax. In general, R code
is often somewhat unreadable, and the lack of a string concatenation
operation is one of the worst imo, so I have say something here.

"+" in R does not have this problem that JavaScript has above, because
minus does not convert strings to numbers. "We" do not want the define the
two-operand minus operation for strings, either. I.e. "we" (I, really) want

> "2" + "1"
[1] "21"
> "2" - "1"
Error in "2" - "1" : non-numeric argument to binary operator
> "2" - - "1"
Error in -"1" : invalid argument to unary operator

What is wrong with this, again?

Btw. there are several languages with string concatenation operators, and
without the JS problem you mentioned, e.g. this is Python:

>>> "2" + "1"
'21'
>>> "2" - "1"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'str'
>>> "2" - - "1"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary -: 'str'

Gabor

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel