From lgautier at gmail.com  Mon Nov 30 20:03:15 2009
From: lgautier at gmail.com (Laurent Gautier)
Date: Mon, 30 Nov 2009 20:03:15 +0100
Subject: [Rd] :Re:  PROTECT and OCaml GC.
In-Reply-To: <4B140136.5030100@citycable.ch>
References: <mailman.15.1259578805.1160.r-devel@r-project.org>
	<4B13D956.7030608@gmail.com> <4B13DDB9.5060703@citycable.ch>
	<4B13EB34.8090207@gmail.com> <4B140136.5030100@citycable.ch>
Message-ID: <4B1416F3.3010703@gmail.com>

Guillaume Yziquel wrote:
> Laurent Gautier a ?crit :
>>
>> Anonymous R objects, that is without an associated symbol in R, can be 
>> passed to functions (and in that way makes a binding "take hold of R 
>> objects without using symbols").
>> For example, building R code made of anonymous objects can be achieved 
>> by making a LANGSXP object and tweaking it.
>>
>> Example in R itself:
>>  > x <- call("round", 2.3)
>>  > eval(x)
>> [1] 2
>>  > x[[1]] <- function(x) x^2
>>  > eval(x)
>> [1] 5.29
>>
>> Getting more complex constructs may need a little more trickery.
>>
>> ...or do you mean something else ?
>>
>> L.
> 
> You're saying "anonymous R objects can be passed to functions". My 
> question is:
> 
> can you construct a LANGSXP in C/Python/rpy from R objects and an 
> anonymous R closure, the closure being available from C as a SEXP 
> closure. Can you write a function
> 
>     SEXP my_langsxp (SEXP closure, SEXP arglist);
> 
> with only the API?
> 

If this can be done from R itself, it can be done from the C level.

I have not looked into making sure that this can precisely and 
effortlessly be done with rpy2, as ironing other parts of the bridge 
caught my attention and seemed more urgently needed, but I remember 
contemplating the idea of having it working at some point...
(I went as far as getting LANGSXP objects exposed as Python list-like 
objects, I think).



[Rd] :Re: PROTECT and OCaml GC.
Laurent Gautier