[Rd] design question

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
18 Jun 2000 11:56:27 +0200

Bill Venables <venables@acland.qld.cmis.csiro.au> writes:

> > here is an example
> > Outer[#1^2 + #2^2 &, {1, 2}, {3, 4}]
> Cryptic for most users, I'd say, and very macro-like.
> > 
> > in some cases, this notation is quite convenient.
> > and since r is lexically scoped, it also should not be too dangerous.
> > what do our architects think about introducing this kind of notation
> > in r?
> It has to have very low priority, possibly negative.  If syntactic
> revisions were ever seriously contemplated, I would strongly favour
> trying to bring in some of the S4 changes, but even there I would
> regard the semantic extensions as much more urgent than the purely
> syntactic ones.  Consistency with S-PLUS is not the final arbiter of
> everthing but it does really matter.

We do have a couple of cases where we allow expressions instead of
functions of one variable, with "x" marking the spot of the
indep.var., e.g. curve(exp(x)) works that way.

In principle we could allow a similar convention for functions of two
variables, e.g. outer(u, v, x^2 + y^2). There are various nasty
pitfalls in the kind of code needed to support this, though: For
instance, writing a function that passes its argument on to curve()
needs to do it with substitute() magic and evaluation in parent
frames. Also take a look at the beginning of curve() for the
contorsions the code needs to go through to handle the non-function
cases. On the whole, I'm not sure this kind of apparent
user-convenience is worth it.

BTW, we also have positional TeX-style arguments, but fortunately
nobody knows about them:

> f<-function(...)..1^2+..2^2
> f(2,3)
[1] 13

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch