Thank you, Gabe and Bill,
for taking up the discussion.
William Dunlap <wdunlap at tibco.com>
on Thu, 8 Sep 2016 10:45:07 -0700 writes:
> Prior to the mid-1990s, S did "length-0 OP length-n -> rep(NA, n)"
> was changed
> to "length-0 OP length-n -> length-0" to avoid lots of problems like
> any(x<0) being NA
> when length(x)==0. Yes, people could code defensively by putting
> if(length(x)==0)...
> in their code, but that is tedious and error-prone and creates
Yes, so actually, basically
length-0 OP <anything> -> length-0
Now the case of NULL that Bill mentioned.
I agree that NULL is not at all the same thing as double(0) or
logical(0),
*but* there have been quite a few cases, where NULL is the
result of operations where "for consistency" double(0) / logical(0)
should have
been.... and there are the users who use NULL as the equivalent
of those, e.g., by initializing a (to be grown, yes, very inefficient!)
vector with NULL instead of with say double(0).
For these reasons, many operations that expect a "number-like"
(includes logical) atomic vector have treated NULL as such...
*and* parts of the {arith/logic/relop} OPs have done so already
in R "forever".
I still would argue that for these OPs, treating NULL as logical(0) {which
then may be promoted by the usual rules} is good thing.
> Is your suggestion to leave the length-0 OP length-1 case as it is
> length-0 OP length-two-or-higher an error or warning (akin to the
That's exactly what one thing the current changes eliminated:
arithmetic (only; not logic, or relop) did treat the length-1
case (for arrays!) different from the length-GE-2 case. And I strongly
believe that this is very wrong and counter to the predominant
recycling rules in (S and) R.