[R] Scheme in R

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Dec 6 23:29:19 CET 2001


Ed Kademan <kademan at phz.com> writes:

> The initial authors of R said¹, "...we implemented the language by
> first writing an interpreter for a Scheme subset and then
> progressively mutating it to resemble S."  Further on in that article
> they elaborated that their strategy was to create a parser that would
> take expressions in S-like syntax and translate them to Scheme
> S-expressions.
> 
> Does R still work that way?  Can R be made to accept Scheme syntax
> directly?  Can you build it in such a way that when you start it up
> you get a Scheme read-eval-print-loop instead of the S-like
> interactive environment?  I ask simply because I happen to like
> Scheme/Lisp syntax.  But it also occurred to me that---considering the
> ease with which you can implement specialized little languages in
> Scheme---such an interface might make it easier to experiment with
> things like extensions to model and graphics formulae.
> 

Well, ... where do I start? The R (and to some extent also S)
internals are still very Lisp/Scheme like. The parser/evaluator hasn't
changed that much since the early versions of R. Perhaps the most
notable change is that a list object is not a dotted-pair list as in
Lisp anymore but a generic vector. (The pairlist object type still
exists, but is hardly ever used.) If you try picking apart an
expression using [[...]] you will see that almost everything maps to a
Lisp-like syntax, e.g.

 quote(x <- 2 + 3)

is essentially (<- x (+ 2 3)). Some slightly peculiar cases involve
for loops and expressions with non-local returns like break, and
return(). The evaluation model is somewhat non-Scheme because of the
lazy evaluation and substitute() aspects.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list