Duncan Murdoch wrote: > 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. > > Exactly. But the issue in that case is not a difference on the order of Machine$double.eps but between "24" and "222" (from "2"+2+2).
Still, even numbers act up once you get into recycling rules: Try 1:2+1:3+1:4 (We've been here before, haven't we?) > Duncan Murdoch > > ______________________________________________ > R-help@r-project.org 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. > -- O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ R-help@r-project.org 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.