[Rd] [R] are arithmetic comparison operators binary?

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Feb 24 10:13:22 CET 2009


Martin Maechler wrote:
>
>     >> Thank you, Wacek, 
>     >> though .. "wrong mailing list" 
>     >> 
>
>     WK> apologies.  i was actually asking for explanation, assuming that it
>     WK> might be my misunderstanding, rather than reporting a bug.
>
> ( yes; but it is really a technical topic, also touching on
>   extending R [below], hence --> R-devel )
>   

point taken.

> I think we'd gladly accept well-written & commented extra
>   <R-x.y.z>/tests/foo.R  
> files or patches to existing ./tests/*.R 
> particularly if the contributor shows the new tests are
> systematically covering currently untested areas...
> Again: this really belongs to R-devel
>
>   

ok.

>     WK> plus those undocumented, but assumed by the developers.
>
>   ;-) :-)
>
> Indeed, we are also grateful for (concise!) patches to  man/*.Rd
> help files.
>   

ok.

>     >> If you'd looked a bit in the sources, you'd seen that they
>     >> really are supposed to be binary only.
>     >> 
>
>     WK> it wouldn't be nonsensical to let them be of arbitrary arity (in a
>     WK> well-documented manner), though it might confuse users.
>
> Yes (to the latter).  One of the beauties of S and R is the
> syntax closeness to  mathematical notation.
> Many of us know that  Lisp  has beauties that S can never have,
> but that's really in different beauty-space. 
>   

not quite sure what you mean by 'closeness to mathematical notation' here.


>     WK> just a question (i haven't checked the sources, maybe i should):  what
>     WK> is it that happens when one of the operators is called with n = 0 or 1
>     WK> argument?  how does it come up with logical(0) rather than NA?
>
> In some of the cases  e.g. 
>    '<'(1)   
>
> it basically does   [empty] < 1  and hence returns the same as
>
>    NULL < 1
>   
which is consistent with NULL + 1.  btw:

1. you might want to keep the error message from applying < and other
relops to an inappropriate number of arguments in sync with the message
one gets from, e.g., '+'(1,2,3).  (you may want to actually update the
message from '+' and relatives, as it seems that there are more
operators that give an error message similar to that of '<'.  the
attached patch fixes this; it has been compiled and successfully tested
-- see below.)

2. '+'() and '+'(1,2,3) say the operator needs one or two arguments, but
again, '+' is documented as a *binary* operator.  i guess the intention
here is to have them unary or binary, and it's the docs that should be
updated.

vQ


The patch for src/main/arithmetic.c was prepared as follows:

svn co https://svn.R-project.org/R/trunk/
cd trunk
tools/rsync-recommended
# modifications made to src/main/character.c
svn diff > do_grep.diff

The patched sources were successfully compiled and tested as follows:

svn revert -R .
patch -p0 < do_grep.diff
./configure
make
make check



-------------- next part --------------
A non-text attachment was scrubbed...
Name: arithmetic.diff
Type: text/x-diff
Size: 509 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20090224/d06f659d/attachment.bin>


More information about the R-devel mailing list