From murdoch at stats.uwo.ca  Fri Dec 10 14:38:34 2004
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri Dec 10 14:38:46 2004
Subject: [Rd] Re: [R] Is  k  equivalent to  k:k ?
In-Reply-To: <16825.24334.69465.599617@gargle.gargle.HOWL>
References: <200412100137.iBA1bGMV054978@atlas.otago.ac.nz>
	<16825.24334.69465.599617@gargle.gargle.HOWL>
Message-ID: <n59jr0hiug8rvg6k1rmeos17bi9k66tdob@4ax.com>

On Fri, 10 Dec 2004 09:32:14 +0100, Martin Maechler
<maechler@stat.math.ethz.ch> wrote :

>    RichOK> If you want to pass seq(length=n) to a .C or
>    RichOK> .Fortran call, it's not helpful that you can't tell
>    RichOK> what the type is until you know n!  It would be nice
>    RichOK> if seq(length=n) always returned the same type.  I
>    RichOK> use seq(length=n) often instead of 1:n because I'd
>    RichOK> like my code to work when n == 0; it would make life
>    RichOK> simpler if seq(length=n) and 1:n were the same type.
>
>now if that really makes your *life* simpler, what does that
>tell us about your life  ;-) :-)
>
>But yes, you are right.  All should return integer I think.

Yes, it should be consistent, and integer makes sense here.

However, as a matter of defensive programming, one should almost
always explicitly set the type (using  as.integer for example) in a .C
or .Fortran call:  those languages care quite a bit about the storage
mode, and give bizarre and hard to debug errors when it is wrong.   If
you did this, you wouldn't care that seq(length=n) returns mode
double.

It might waste a few cpu cycles, but programmer debugging cycles are
much more expensive.  

Duncan Murdoch


[Rd] Re: [R] Is k equivalent to k:k ?
Duncan Murdoch