# [R] R and Scheme

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Dec 11 01:35:56 CET 2008

```Wacek Kusnierczyk wrote:
> Peter Dalgaard wrote:
>> Johannes Huesing wrote:
>>> Stavros Macrakis <macrakis at alum.mit.edu> [Wed, Dec 10, 2008 at
>>> 04:59:25AM CET]:
>>>> So I conclude that what is really meant by "R semantics are based on
>>>> Scheme
>>>> semantics" is "R has functions as first-class citizens and a correct
>>>> implementation of lexical scope, including upwards funarg".
>>>>
>>> One other thing reminiscient of Lisp is the infix notation (as in
>>> "+"(1, 3)), which the authors have sprinkled with enough syntactic
>>> sugar that the users
>>> needn't be bothered with. To the benefit of ubiquity, I'd think.
>>>
>> That's prefix notation, infix is "1+3" (and postfix is "1,3,+" as in
>> old HP calculators). But you're right that R has Lisp-like parse trees
>> with a thin layer of syntactic sugar:
>>
>> Lisp writes function calls as (f x y) for f(x,y) and (+ 1 3) for 1+3.
>> In R we have
>>
>>> e <- quote(f(x,y))
>>> e[[1]];e[[2]]; e[[3]]
>> f
>> x
>> y
>>> e <- quote(1+3)
>>> e[[1]];e[[2]]; e[[3]]
>> `+`
>> [1] 1
>> [1] 3
>>
>
> the reminiscence is limited, though.  the following won't do:
>
> `+`(1,2,3)
>
> and
>
> quote(1+2+3)
>
> is not a list of `+`, 1, 2, and 3.
>
> vQ

Essentially irrelevant. You have to distinguish between form and
function, and it is not important that the two languages contain
slightly different definitions and semantics of particular functions.
The point is that the general _form_ of the parse tree is the same.

Because of the syntactic sugar, R does not have `+` equivalent to `sum`
like LISP does. `+` is a binary (or unary) operator and 1+2+3 parses as
LISPs

(+ (+ 1 2) 3).

--
O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907

```