[R] Scheme in R

Ed Kademan kademan at phz.com
Sun Dec 9 16:28:30 CET 2001


Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes in reply to my
question about whether R can be made to behave more like Scheme:
> 
> 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.
> 

I didn't expect there to be a simple answer to this question and I am
sure that with lazy evaluation and all the tools available for
computing on the language one can programmatically analyze and
transform R code in at least roughly the same sorts of ways as with
Scheme or Lisp.  (The article¹ in Rnews by Thomas Lumley about
developing an R macro processor is a good example.)  But I have been
trying to automate the conversion of a large file of C code lately and
that task has made me appreciate the beauty of an utterly simple and
transparent syntax based on s-expressions.

By the way there is a very interesting ongoing discussion about this
general topic and related ones in the lightweight languages workshop
and mailing list².  That is, there is nothing there about R
specifically but apparently Perl and Python are facing major changes
and some discussants have suggested that it would be a good idea if
those languages moved closer to Scheme internally.

Thank you for your response.

1. http://cran.r-project.org/doc/Rnews/Rnews_2001-3.pdf
2. http://ll1.mit.edu

-- 
Ed Kademan              508.651.3700
PHZ Capital Partners    508.653.1745 (fax)
321 Commonwealth Road   <kademan at phz.com>
Wayland, MA 01778
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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