From venables@acland.qld.cmis.csiro.au  Sun Jun 18 08:57:29 2000
From: venables@acland.qld.cmis.csiro.au (Bill Venables)
Date: Sun, 18 Jun 2000 17:57:29 +1000
Subject: [Rd] design question
In-Reply-To: Your message of "Sun, 18 Jun 2000 08:53:07 +0200."
 <394C71D3.B490F97A@univie.ac.at>
Message-ID: <200006180757.RAA24273@snowy.nsw.cmis.CSIRO.AU>

Erich Neuwirth asks:

> let me ask you as possibly very silly question.
> 
> what  would you think of a shorthand notation for anonymous fuctions in
> arguments?
> 
> let me illustrate this in how mathematica does it.
> 
> mathematica has a function notation like R
> 
> Map[Function[x, x^2], {1, 2, 3}]
> 
> this can be abbreviated as
> Map[#^2 &, {1, 2, 3}]

The Maple notation is more understandable to most people:

	map(x -> x^2, {1, 2, 3})

but of course "->" is already taken in S/R as the right pointing
assignment operator (although maybe I'm the only one who even knows
about it, let alone uses it...)

> 
> & indicates a function expression,
> and # is the (one) anonymous argument.
> functions with more that one arguments
> (whch are positional) can be written as
> #1  #2
> and so on

Either swiped from TeX or both have swiped the idea from a common
source.  It has the look of a macro language, which can be misleading.

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

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


[Rd] design question
Bill Venables