From thomas.friedrichsmeier at ruhr-uni-bochum.de  Wed Apr 18 14:17:02 2007
From: thomas.friedrichsmeier at ruhr-uni-bochum.de (Thomas Friedrichsmeier)
Date: Wed, 18 Apr 2007 14:17:02 +0200
Subject: [Rd] args / formals on primitives
In-Reply-To: <Pine.LNX.4.64.0704161823240.10009@gannet.stats.ox.ac.uk>
References: <200704161853.07237.thomas.friedrichsmeier@ruhr-uni-bochum.de>
	<Pine.LNX.4.64.0704161823240.10009@gannet.stats.ox.ac.uk>
Message-ID: <200704181417.03020.thomas.friedrichsmeier@ruhr-uni-bochum.de>

On Tuesday 17 April 2007 09:12, Prof Brian Ripley wrote:
> On Mon, 16 Apr 2007, Thomas Friedrichsmeier wrote:

[...]

> > While at it, I was wondering, why
> >
> > formals(c)
> >
> > still returns NULL, in contrast.
>
> Because only closures have formals, the way things are defined.  This
> makes sense to me as formals<-() cannot work on primitives.

On the other hand, a return value of NULL does not differentiate between a 
closure which simply does not have any formals and a primitive:

f <- function () 1
formals (f)		# NULL
formals (c)	# NULL

In the former case, formals<-() will work, in the latter case, it won't. To 
differentiate between those, one could use is.primitive() or typeof().

I don't pretend to understand the technicalities involved, but to me it looks 
like there is some effort to make all types of functions "look" the same in R 
for most purposes. Having the same in formals() would make it slightly easier 
to provide argument completion or object browsers (but then, args() could be 
used for such purposes).

Either way it's painless to me, and is now clearly documented. So if this does 
not make too much sense, just ignore me.

Regards
Thomas Friedrichsmeier



[Rd] args / formals on primitives
Thomas Friedrichsmeier