From b.rowlingson at lancaster.ac.uk  Thu May  8 09:35:50 2014
From: b.rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Thu, 8 May 2014 08:35:50 +0100
Subject: [Rd] precedence (was 'historical NA question')
In-Reply-To: <bdd4090e97ac4d7eab36c01d6dafd758@EX-1-HT0.lancs.local>
References: <3dfcdc$gnkvcv@ironport9.mayo.edu> <536A5C52.4030907@r-project.org>
	<536A8B72.802@fhcrc.org>
	<7CC02BBE-3F5D-4A11-87A1-F8B013BD081F@r-project.org>
	<AD68281E-B44C-4DB3-9CE5-D513550C84A6@gmail.com>
	<536AA877.4010301@fhcrc.org>
	<8D2277DD-434F-4FD4-B866-4EC8F1441902@r-project.org>
	<bdd4090e97ac4d7eab36c01d6dafd758@EX-1-HT0.lancs.local>
Message-ID: <CANVKczMrqLtZFaOTns-f6XDRKp4CDS_5XH9MORfgYemxnUoAtA@mail.gmail.com>

On Wed, May 7, 2014 at 11:00 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> 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.



[Rd] precedence (was 'historical NA question')
Barry Rowlingson