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
[1] FALSE
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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.