FEXPRs and first class environments in R

101 views
Skip to first unread message

Oto Havle

unread,
Dec 25, 2013, 4:28:25 PM12/25/13
to kl...@googlegroups.com
Hi,

I've stumbled on a comment that R is "a live language that has fexpr"

> http://augustss.blogspot.cz/2011/05/more-points-for-lazy-evaluation-in.html#2078787681653606742

I have no experience with R, but it seems to be true. I'm surprised
I missed it before. FEXPR-style call-by-text is used to print plot
labels of expressions passed to plotting function:

> http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Substitutions

R has also lexical scope and first class environments, quote, eval...

> http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Environment-objects

The environments are not encapsulated, the parent environment
can be extracted, or modified. On the other hand, it is possible
to lock an environment or a binding:

> R version 2.14.1 (2011-12-22)
> > "if" <<- 1
> Error: cannot change value of locked binding for 'if'

There are projects about compiling R to C and bytecode. I wonder
what a compiler could do with this language.

Regards,

Oto Havle.

Andres Navarro

unread,
Dec 26, 2013, 8:45:34 AM12/26/13
to kl...@googlegroups.com
I've only used R casually in some statistics class so this really surprised me.
It's certainly worth investigating.  I suspect that the compilers don't do anything
with code that uses the fexpr-like facilities (i.e. they just pass it on to an interpreter
 at runtime), but I hope I'm wrong!

I found interesting that they use promises as operands, so every time a function
is called it gets each argument with a value slot (for memoization), the expression
(for fexpr style access) and an environment (for evaluation of the promise). 
This is (almost) exactly the representation of promises in the kernel report
(except for the boolean tracking whether the value has already been computed).

But other than that, it's interesting in that the arguments and the expressions are
explicitly tied together (where in kernel the environment is another argument and
you have to manually evaluate each expression in the corresponding env)

Ray Dillinger was pursuing a similar idea as can be seen in this comment on LtU:
http://lambda-the-ultimate.org/node/3861#comment-57996 (the whole thread is
very interesting, there's comments by John Shutt on Kernel and Thomas Lord on
a simplified proposal for scheme).

Regards,
Andres Navarro





--
You received this message because you are subscribed to the Google Groups "klisp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to klisp+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages