[Rd] design question

Bill Venables venables@acland.qld.cmis.csiro.au
Mon, 19 Jun 2000 09:00:45 +1000

> 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.

Yes, but that doesn't require any syntactic change, it's already
there.  If people want to write functions that way, it's up to them.

> 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.

I'm pretty sure it's not worth it.  Utlimately it leads to user
confusion when a variety of different kinds of object are allowed in
various places only to have them ultimately coerced to the same thing.
I know this is sometimes pretty well unavoidable, such as with
outer(u, v, "+") but overall I think it is something to be avoided.

> 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

Oh I knew about it all right, Peter.  It's just that *I* never told
anyone about it...  :-) 

Bill Venables.
Bill Venables,      Statistician,     CMIS Environmetrics Project
CSIRO Marine Labs, PO Box 120, Cleveland, Qld,  AUSTRALIA.   4163
Tel: +61 7 3826 7251           Email: Bill.Venables@cmis.csiro.au    
Fax: +61 7 3826 7304      http://www.cmis.csiro.au/bill.venables/

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