[Rd] PROTECT and OCaml GC.

Guillaume Yziquel guillaume.yziquel at citycable.ch
Mon Nov 30 19:14:18 CET 2009


Simon Urbanek a écrit :
> 
>> Because I've been unable to find what exactly applyClosure or eval 
>> requires, when it comes to the structure of the argument LANGSXP. For 
>> example.
>>
> 
> LANGSXP is simply a pairlist representing the expression, e.g. to look 
> at "a+2" expression:
> 
>  > .Internal(inspect(quote(a+2)))
> @1183698 06 LANGSXP g0c0 []
>   @101080c 01 SYMSXP g0c0 [MARK,gp=0x4000] "+"
>   @1130394 01 SYMSXP g0c0 [MARK] "a"
>   @1c384e8 14 REALSXP g0c1 [] (len=1, tl=0) 2
> 
> I would suggest you learn more about R first - this is all accessible at 
> the R/S language level:
> 
>  > x
> a + 2
>  > x[[1]]
> `+`
>  > x[[2]]
> a
>  > x[[3]]
> [1] 2

I've gathered that LANGSXP and LISTSXP are structured in this way. By 
reading the header files. Please see:

https://stat.ethz.ch/pipermail/r-devel/2009-November/055813.html

Now to continue one the topic of the top paragraph:

I've tried sending a LANGSXP where the CAR element is a SYMSXP. eval 
workd. I've tried sending a LANGSXP where the CAR element is a CLOSXP. 
eval doesn't work. This is what I meant about the "structure of the 
argument LANGSXP". And it's contained in the link above.

And it goes then to my other question: How can you pass to eval a 
LANGSXP where the CAR is an *anonymous* function, no SYMSXP involved?

This does not seem documented in R-ints.pdf, R-exts.pdf or R-lang.pdf.

>> Suppose I have an OCaml (or pure C if you wish) linked list of OCaml 
>> value wrapping SEXP values. Is it possible, using only the API, to 
>> create a LANGSXP / LISTSXP list out of these SEXPs?
> 
> Of course - see CONS/LCONS.

Great. That's the kind of fruitful interaction that could have made me 
gain a few days and not bypass the API. Thanks.

>> The "general" aspect of my request therefore concerns bindings to 
>> languages with 'inferred polymorphic static typing'. Please understand 
>> what these languages are about before dismissing my remarks as "my 
>> way". You may not care, you wouldn't be the first.
> 
> You're missing my point - "your way" was to hack into the internals of 
> how R represents SEXPs (going down to each pointer inside the SEXP 
> headers). None of the above applies to my remark.
> 
> Cheers,
> Simon

You're also missing my point. "my way" is the only way I've come up with 
to examine how to make sure that the static typing system I'm putting in 
place fits with the internal structure of SEXPs. I do need to know the 
internal structure of sexps and the way they evolve under the influence 
of function such as eval, install, applyClosure, in order to statically 
type my code. Same link expressing this concern:

https://stat.ethz.ch/pipermail/r-devel/2009-November/055813.html

Documentation is terse on precise structure of sexps. You get 
description of individual sexps, not a *precise* description of how they 
are assembled, which is what the typing will have to express. Much in 
the same spirit as the link below, which I really entice you to read:

http://ocsigen.org/eliom/manual/1.2.0/1#p1baseprinciples

Statically typing the internal structure of assembled sexps is no 
different than statically typing XHTML.

Glad that we're heading somewhere...

All the best,

-- 
      Guillaume Yziquel
http://yziquel.homelinux.org/



More information about the R-devel mailing list