From ggrothendieck at gmail.com  Mon Jul 24 14:37:23 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 24 Jul 2006 08:37:23 -0400
Subject: [Rd] RFC: Redefining length(<POSIXlt>) ?
In-Reply-To: <17604.42235.324954.796411@stat.math.ethz.ch>
References: <44C32276.30800@univ-fcomte.fr>
	<644e1f320607230341v6d4cde82i1eff7881cc36a6ac@mail.gmail.com>
	<44C36849.7070106@univ-fcomte.fr>
	<971536df0607230602u33348346x8093c6b9a9984f97@mail.gmail.com>
	<17604.38621.799499.786355@stat.math.ethz.ch>
	<17604.42235.324954.796411@stat.math.ethz.ch>
Message-ID: <971536df0607240537o2ad63be6v61c50023c7f35b3b@mail.gmail.com>

I think Spencer's point of it likely being compatible with most
current code is important (since it currently always returns
9 so its unlikely to be used meaningfully in existing code).

On 7/24/06, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
> So I did open a new subject and move the discussion to R-devel
> now.
>
> >>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
> >>>>>     on Mon, 24 Jul 2006 11:46:05 +0200 writes:
>
>  >>>>> "Gabor" == Gabor Grothendieck <ggrothendieck at gmail.com>
>  >>>>>     on Sun, 23 Jul 2006 09:02:35 -0400 writes:
>
>      Gabor> Looking at the diff.POSIXt code we see the problem is
>      Gabor> that it takes the length of the input using length
>      Gabor> which is wrong since in the case of POSIXlt the
>      Gabor> length is always 9 (or maybe length should be defined
>      Gabor> differently for POSIXlt?).
>
>    MM> Though I agree with Spencer that a user may expect
>    MM> length() to behave differently, but I don't think this
>    MM> would be a good idea.  Yes, length() is generic, but its
>    MM> help() emphasizes that for lists, length() should be the
>    MM> number of list elements.  Of course anyone one *can*
>    MM> define length() methods that behave differently for
>    MM> his/her classes, but then one would also want to make
>    MM> sure that e.g.  x[length(x)] or 'x[length(x)] <- value'
>    MM> works and -- in a case of simple S3 class built on a
>    MM> list, would work differently than if x was a the simple list.
>
> Hmm, after thinking a bit more, and particularly after seeing
> all the other methods we already have working for "POSIXlt",
> I'm much less sure if  (re)definining  length(<POSIXlt>)
> would be such a bad idea.
> Indeed, "[", and "[<-" and "[[" already work with an implicit
> length of 'length_of_series' and not length 9, and so does str().
>
> So it seems to me, there is more reasonable momentum *for* a
> length.POSIXlt() method than I first considered.
>
> Still not sure what the wisest decision would be, and I am
> asking for more opinions or arguments pro / con.
> Since Brian Ripley has done the most work on the POSIX[cl]?t
> classes, we should also wait on his opinion.
>
> Martin
>
>    MM> In my view, I would only consider redefing length() for
>    MM> "non-basic" S4 classes, i.e. those with slots, where no
>    MM> confusion is possible, since these objects are
>    MM> definitely not simple vectors nor lists (aka "generic"
>    MM> vectors).
>
>



[Rd] RFC: Redefining length(<POSIXlt>) ?
Gabor Grothendieck