[R] R and Scheme
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Thu Dec 11 15:41:43 CET 2008
Peter Dalgaard wrote:
> 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.
and what does the form of the syntax tree have to do with
lisp-likeness? in java, c, etc., the string "1 + 2 + 3" would be parsed
into a tree that has the same shape as in the case of r: a '+' in the
root, '1' in one branch, and in the other branch a tree with a '+' as
the root and '2' and '3' in the branches.
"The point is that the general _form_ of the parse tree is the same." --
does it make java or c resemble lisp?
>
> 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).
the point is, it's not a problem of the binary-ness of the particular
function `+`. it's that an expression where the same operator is used
infix more than once in a row is parsed and evaluated as a nested
sequence of calls, not as a single call with multiple arguments:
`%+%` = function(a, b, c=0) { print (c(a,b,c)); a+b+c }
1 %+% 2 %+% 3
`%+%`(1,2,3)
vQ
More information about the R-help
mailing list