[R] R as a programming language

Duncan Murdoch murdoch at stats.uwo.ca
Thu Nov 8 19:02:22 CET 2007

On 11/8/2007 11:51 AM, Thomas Lumley wrote:
> On Wed, 7 Nov 2007, Duncan Murdoch wrote:
>> At first I thought you were complaining about the syntax, which I find
>> ugly.  There was a proposal last year to overload + to do concatenation
>> of strings, so you'd type cat("x=" + x + "y=" + y + "\n"), but there was
>> substantial resistance, on the grounds that + should be commutative.
> My objection, at least, was that + should be *associative*.  I don't think 
> anyone would expect a + b and b+a to be the same for strings, but I do 
> think the fact that (a+b)+c and a+(b+c) would be different (if some of a, 
> b,c were strings) has real potential for ugliness.

Sorry, I forgot about that. I think there were complaints about both 
commutativity and associativity.

I do think lack of associativity is a less impressive complaint, because
it doesn't even hold for floating point addition without mixing types:

 > x <- .Machine$double.eps/2
 > A <- (1 + x) + x
 > B <- 1 + (x + x)
 > A == B

As far as I can see, string concatenation would only lose associativity 
when some of the operands were automatically converted to strings. 
Mixed type operations often give surprising results.

Duncan Murdoch

More information about the R-help mailing list