[6330] in s-news-athena

home help back first fref pref prev next nref lref last post

Zero-argument functions

daemon@ATHENA.MIT.EDU (Russ Lenth)
Tue Jan 31 14:16:06 1995

Date: Tue, 31 Jan 95 12:46:30 CST
From: rlenth@stat.uiowa.edu (Russ Lenth)
To: s-news@utstat.toronto.edu

Paul Tukey responded to my earlier posting on quitting S as follows...

> Why not go one step further and add:
> 
>     class(q) <- "QUIT"
> 
> Then even "q" would have the desired effect!

That got me to thinking...  Define a print method like this:

	print.CHEAT <- function(fcn)
		get(as.character(substitute(fcn)))()

Now, you can make any zero-argument function execute
without parentheses.  For example,

	class(q) <- "CHEAT"
	class(help) <- "CHEAT"
	class(X11) <- "CHEAT"

creates parenthesis-free commands "q", "help", and "X11".

There's undoubtedly a more refined method that does not require
one to make a private copy of a whole function.

------------------------------------------------  --------------,
Russ Lenth                 rlenth@stat.uiowa.edu  \              )
Department of Statistics                           |             \_ "The Athens
  and Actuarial Science    Tel: (319)335-0814      \    Iowa City  \ of the
The University of Iowa     FAX: (319)335-3017       \          *  _/ Midwest"
Iowa City, IA 52242  USA   CW:  *= * ====== *=*      |           /
------------------------------------------------      ----------v

home help back first fref pref prev next nref lref last post