Skip to content
Prev 31824 / 63424 Next

surprising behaviour of names<-

Berwin A Turlach wrote:
*supposedly*
we know how a lot of built-ins hack around this, don't we, and we also
know that call-by-value is not really the argument passing mechanism in r.
indeed!  that's what i have said previously, no?  there is still space
for the smart (i mean it) copy-on-assignment behaviour, but it should
not be visible to the user, in particular, not in that 'names<-'
destructively modifies the object it is given when the refcount is 1. 
in my humble opinion, there is either a design flaw or a bug here.
seems to suggest?  is not the purpose of documentation to clearly,
ideally beyond any doubt, specify what is to be specified?
are you suggesting fortune telling from what the docs do *not* say?
since?  it doesn't!
yes, that's what i'd expect in a functional language.
i got lost in your argumentation.  i have given examples of where
'names<-' destructively modifies and returns the updated object, not a
copy.  what is your point here?
are you suggesting fortune telling from the fact that a variable *tmp*
is used?
not really, unless you mean the returned object in the referential sense
(memory location) versus value conceptually.  here x will obviously have
the value of the original x plus the names, *but* indeed you cannot tell
from this snippet whether after the assignment x will be the same,
though updated, object or will rather be an updated copy:

    x = c(1)
    x = 'names<-'(x, 'foo')
    # x is the same object

    x = c(1)
    y = x
    x = 'names<-'(x, 'foo')
    # x is another object

so, as you say, it is not well defined with what object will x end up as
its value, though the value of the object visible to the user is well
defined.  rewrite the above and play:

    x = c(1)
    y = 'names<-'(x, 'foo')
    names(x)

what are the names of x?  is y identical (sensu refernce) with x, is y
different (sensu reference) but indiscernible (sensu value) from x, or
is y different (sensu value) from x in that y has names and x doesn't?
nonsense, it's a *completely* different issue.  here you touch the issue
of the order of evaluation, and not of whether an object is copied or
modified;  above, the inverse is true.

in fact, your example is useless because the result here is clearly
specified by the semantics (as far as i know -- prove me wrong).  you
lookup i (0) and i (0) (the order does not matter here), add these
values (0), assign to i (0), and increase i (1). 

i have a better example for you:

    int i = 0;
    i += ++i - ++i

which will give different final values for i in c (2 with gcc 4.2, 1
with gcc 3.4), c# and java (-1), perl (2) and php (1).  again, this has
nothing to do with the above.
but this must be nonsense, since:

    x = 1
    'names<-'(x, 'foo')
    names(x)
    # NULL

    x = 1
    names(x) <- 'foo'
    names(x)
    # "foo"

clearly, there is not only syntactic difference here.  but it might be
that 10.1.2 does not suggest anything like what you say.
as i explained a few months ago, i study r to find examples of bad
design.  if anyone in the r core is interested in having the problems i
report fixed, i'm happy to get involved in a discussion about the design
and implementation.  if not, i'm happy with just pointing out the issues.

cheers,
vQ

Thread (49 messages)

Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Peter Dalgaard surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Stavros Macrakis surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Wacek Kusnierczyk surprising behaviour of names<- Mar 10 Simon Urbanek surprising behaviour of names<- Mar 11 Simon Urbanek surprising behaviour of names<- Mar 11 Wacek Kusnierczyk surprising behaviour of names<- Mar 11 Wacek Kusnierczyk surprising behaviour of names<- Mar 11 Berwin A Turlach surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Simon Urbanek surprising behaviour of names<- Mar 12 G. Jay Kerns surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Joshua Ulrich surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 12 Berwin A Turlach surprising behaviour of names<- Mar 12 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Berwin A Turlach surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 William Dunlap surprising behaviour of names<- Mar 13 Tony Plate surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Tony Plate surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Berwin A Turlach surprising behaviour of names<- Mar 13 Wacek Kusnierczyk surprising behaviour of names<- Mar 13 Thomas Lumley surprising behaviour of names<- Mar 14 Berwin A Turlach surprising behaviour of names<- Mar 14 Wacek Kusnierczyk surprising behaviour of names<- Mar 14 Wacek Kusnierczyk surprising behaviour of names<- Mar 15 Berwin A Turlach surprising behaviour of names<- Mar 15 Thomas Lumley surprising behaviour of names<- Mar 16 Wacek Kusnierczyk surprising behaviour of names<- Mar 16 Wacek Kusnierczyk surprising behaviour of names<- Mar 16