On Tue, 29 Jun 1999, Rolf Turner wrote:
> Many mathematical structures/sequences start ``naturally'' from 0
> rather than from 1, making it convenient to index vectors and array
> dimensions by sequences starting from 0.
In S, the `whole-object' view suggests that this ought to be an
unimportant distinction. But then APL was supposed to encourage
whole-object programming....
[...]
> Question 1: Might the designers of S(plus) consider adding, in some
> future release, a 0-origin switch, say to the options() function? I
> have in mind something like being able to say:
>
> > options(origin=0)
>
> after which
>
> > x[0:3,]
>
> would give me the first, second, third, and fourth rows of the matrix x.
>
> Later I would like to be able to restore normalcy by saying
>
> > options(origin=1)
>
> Would this be feasible/easy/difficult/impossible given S(plus)'s
> internal structure?
>
> It is pretty clear that if you invoked
>
> > options(origin=0)
>
> and then called upon a function which was written assuming 1-origin,
> then the sky would almost surely fall. As far as I'm concerned, that's
> quite alright and it's the user's responsibility to make sure that
> such invocations do not occur.
Including all the system functions like the debugger and anything else
you might want to call? Are you really prepared to take that
responsibility? There are lots of assumptions that [1] or [[1]] is the
first element throughout the code.
> Question 1a: What about R? Would such a feature be any easier
> (or harder?) to incorporate into R?
Almost exactly the same, I reckon.
> Question 2: Am I absolutely correct in asserting that 0-origin is
> not currently available in S(plus)? I.e. is there any sort of
> work-around that would enable one to fake 0-origin in a moderately
> convenient way?
Yes. set the names of the vector to start from 0 and operate via
the names. Better, you could set up a new class, and make the
indexing on that class zero-based. If it really is only indexing that
you need to worry about, that is already generic: you need methods
for [ and [<- and nothing else. I reckon this is a good exercise in
understanding group generics: what do you want to happen when you
add a 1-based vector to a 0-based vector?
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|