[R] Quiz {was "Quit asking me .."}

Henrik Bengtsson hb at maths.lth.se
Wed Sep 17 10:37:01 CEST 2003


Sorry for bugging you AGAIN, but I went to get a coffee and I realized
you can get down to 26 characters:

class(Q)=Q="no";print.no=q

That is a good question to put up on an R/parsing/S3/UseMethod quiz,
ehe?! 

Henrik

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Henrik 
> Bengtsson
> Sent: den 17 september 2003 10:18
> To: 'Deepayan Sarkar'; 'Martin Maechler'; R-help at stat.math.ethz.ch
> Cc: ligges at statistik.uni-dortmund.de
> Subject: RE: [R] Quiz {was "Quit asking me .."}
> 
> 
> First, 42 characters...
> 
> Q="no";class(Q)=Q;print.no=function(x)q(Q)
> 
> Interestingly, the following works too (41 chars)
> 
> Q="";class(Q)=Q;print.=function(x)q("no")
> 
> Is it legal though to have empty class names?
> 
> And finally, the beautiful one with 28 characters
> 
> Q="no";class(Q)=Q;print.no=q
> 
> Have nice day!
> 
> Henrik Bengtsson
> Lund University
> 
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch
> > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> Deepayan Sarkar
> > Sent: den 17 september 2003 09:17
> > To: Martin Maechler; R-help at stat.math.ethz.ch
> > Subject: Re: [R] Quiz {was "Quit asking me .."}
> > 
> > 
> > On Wednesday 17 September 2003 01:36, Martin Maechler wrote:
> > 
> > > How can you write (quite short!) R code such that
> > > typing
> > > 	"Q"
> > >
> > > -- without any  "()" -- will quit R (without asking about saving).
> > >
> > > [But you shouldn't really keep that code active in your standard R
> > > session  because it would be too easy to accidentally 
> shut down R !]
> > >
> > > For the advanced ones:
> > > My shortest solution uses 51 characters of R code, can you
> > beat that?
> > 
> > Barely, 46 removing all spaces:
> > 
> > print.q<-function(x)q("no");Q<-1;class(Q)<-"q"
> > 
> > We can also replace <- by = in recent (and _ in older)
> > versions of R to 
> > decrease this further.
> > 
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> > 
> >
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> 
>




More information about the R-help mailing list