From p.dalgaard at biostat.ku.dk  Sat Oct 30 23:55:46 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Sat Oct 30 23:56:11 2004
Subject: [Rd] Destructive str(...)?
In-Reply-To: <Pine.LNX.4.61.0410301104170.5261@itasca2.stat.uiowa.edu>
References: <Pine.LNX.4.44.0410300859130.4649-100000@gannet.stats>
	<Pine.LNX.4.61.0410301104170.5261@itasca2.stat.uiowa.edu>
Message-ID: <x2brejna59.fsf@biostat.ku.dk>

Luke Tierney <luke@stat.uiowa.edu> writes:
> > str() probably ought to be more cautious when it encounters at external
> > reference or similar exotic object, since it will look at list elements
> > and attributes.
> 
> It's probably just unclass itself, not an issue with NAMED. External
> references are one of a handful of objects that are handled as
> references to mutable objects rather than as immutable values (the
> main other one being environments).  unclass is destructive when
> applied to a reference object.  At some point it might make sense to
> make unclass signal an error when used on a reference object, and
> clean up the things this breaks, including str and a number of other
> print methods.  On the other hand, the same issue exists with all
> attributes on referece objects, so the safest approach is to use a
> wrapper as Brian suggests.

Argh. I think this means that there is a bug in the tcltk code since
tclObj class objects are exactly external references with a class
attribute. It doesn't seem to have bitten anyone yet, though. Or were
you saying that we should fix str() instead?

Anyways, Tcl objects do provide a rather nice illustration of why
reference objects are non-duplicatable (which is the reason behind
unclass being destructive). They have a finalizer that decrements the
Tcl reference count when the R object is destroyed. To avoid bad
things resulting from decreasing the refcount multiple times,
duplication would require an increment of the reference count, and R
just isn't geared to do that: we'd need to introduce something like an
R_RegisterCDuplicator function.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Destructive str(...)?
Peter Dalgaard