behavior of =

Duncan Murdoch dmurdoch@pair.com
Fri, 08 Nov 2002 12:21:34 -0500


On Fri, 8 Nov 2002 08:17:12 -0800 (PST), you wrote:

>On Fri, 8 Nov 2002, Philippe Grosjean wrote:

>> foo(a=b)  # Assignment of b to a, and a is passed as first argument to
>> function foo()
>> foo(a:=b) # b is passed to the named argument 'a' of function foo()
>>
>
>Not only would this require rewriting essentially every piece of R code
>ever written, but even worse, := is used in other languages (and in the
>prehistory of R) as an assignment operator so it would be even less clear
>than the current situation.

I would say a better change (but not good enough to be worth doing,
because it would break so much) would be to drop "=" as an assignment
operator, and use ":=" for that purpose.

A smaller change that might actually be doable would be to have a way
to give anonymous arguments which can be passed only positionally. For
example, put the symbol ANON into the language, and allow functions to
be declared as 

 f <- function(ANON) { .... }

Within the body of f, ANON would act like a named argument, but
name-matching would never work on it, i.e.

 x <- f(ANON=3)

would be a syntax error.  A nicer looking way to do this might be to
allow attributes to be attached to arguments, e.g.

  f <- function(anonymous x) { ... }

but there's nothing like that anywhere else in the language.  This
would have the advantage that you could define min as 

 function (anonymous ..., na.rm = FALSE) 
 .Internal(min(..., na.rm = na.rm))

Doing it with new keywords would probably mean the addition of ANON1,
ANON2, up to some arbitrary number, and ANON... for this case.

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