From gmbecker at ucdavis.edu  Fri Sep  9 21:15:08 2016
From: gmbecker at ucdavis.edu (Gabriel Becker)
Date: Fri, 9 Sep 2016 12:15:08 -0700
Subject: [Rd] R (development) changes in arith, logic,
 relop with (0-extent) arrays
In-Reply-To: <22482.23554.507321.387197@stat.math.ethz.ch>
References: <22469.52585.935914.336374@aragorn.wu.ac.at>
	<22470.37902.198447.925212@stat.math.ethz.ch>
	<22470.38100.993865.828495@aragorn.wu.ac.at>
	<22473.36759.791968.814130@stat.math.ethz.ch>
	<22473.38325.834026.658339@stat.math.ethz.ch>
	<22474.35836.489860.992765@aragorn.wu.ac.at>
	<CAPRP4-eKdb1AKGt73P-+khNXFAWm_4q2PZr69Q7BAjWcXKpSzA@mail.gmail.com>
	<CAPRP4-e4fL=j2xUVMjO-kdmeTfvF=+=9AKrU9+981Xvhwc2MPA@mail.gmail.com>
	<22477.32999.558832.601073@stat.math.ethz.ch>
	<22479.9847.747220.924128@stat.math.ethz.ch>
	<22479.58007.358121.626142@stat.math.ethz.ch>
	<CAHHjBM6yvrgwOFiFAtM+w8BGmdwn114Z6gfyjMEsLQDLV8mA5A@mail.gmail.com>
	<22481.16979.861309.264630@stat.math.ethz.ch>
	<CADwqtCN2PnTFwsrV-K3=hXt64r5eHYNt5dg0OZZdEcDtPOtJuQ@mail.gmail.com>
	<CAF8bMcYBMduLcp_aQoTh74MBBKB9QnTDQG9J_dZyTrFkGd0azw@mail.gmail.com>
	<CADwqtCNXQpg6twfLv1LRscnMa=RND543Kgm1Xn-2APjgsOJWFA@mail.gmail.com>
	<CAF8bMcY8d5Jduf3TtT39+vdD0sAz1fs8hqQ9x0Td9GF=mNGF+Q@mail.gmail.com>
	<22482.23554.507321.387197@stat.math.ethz.ch>
Message-ID: <CADwqtCN5cihoFnoqa0kFbFYmJS-j50kXhaFpNvk0LU_j7TWp7A@mail.gmail.com>

Martin et al.,

I seem to be in the minority here, so I won't belabor the point too much,
but one last response inline:

On Thu, Sep 8, 2016 at 11:51 PM, Martin Maechler <maechler at stat.math.ethz.ch
> wrote:

> 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)"
> and it
>     > 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
> lots of
>     > if(length(x)==0)...
>     > in their code, but that is tedious and error-prone and creates
> really ugly
>     > code.
>
> 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
> but make
>     > length-0 OP length-two-or-higher an error or warning (akin to the
> length-2
>     > OP length-3 case)?
>
> 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.
>

In my view, the recycling rules apply first and foremost to pairs of
vectors of lengths n,m >=1. And they can be semantically explained in that
case very easily: "the shorter, non-zero-length vector is rep'ed out to be
the length of the longer vector and then (generally) an element wise
operation takes place". The zero-length behavior already does not adhere to
this definition, as it would be impossible to do in the case of a
zero-length vector and a nonzero-length vector.

So the zero-length recycling behavior is already special-cased as I
understand it. In light of that, it seems that it would be allowable to
have different behavior based on the length of the other vector.
Furthermore, while I acknowledge the usefulness of the

x = numeric()

x <  5


case (i.e., the other vector is length 1), I can't come up with any use of,
e.g.,

y  = numeric()
y < 3:5


That I can make any sense of other than as a violation of implicit
assumptions by the coder about the length of y.

Thus, I still think that should at *least* warn, preferably (imho) give an
error.

Best,
~G


-- 
Gabriel Becker, PhD
Associate Scientist (Bioinformatics)
Genentech Research

	[[alternative HTML version deleted]]



[Rd] R (development) changes in arith, logic, relop with (0-extent) arrays
Gabriel Becker