From guillaume.yziquel at citycable.ch  Mon Nov 30 19:14:18 2009
From: guillaume.yziquel at citycable.ch (Guillaume Yziquel)
Date: Mon, 30 Nov 2009 19:14:18 +0100
Subject: [Rd] PROTECT and OCaml GC.
In-Reply-To: <F60B92C3-5989-404C-8FEB-1B6002824449@r-project.org>
References: <4B11B75C.9070806@citycable.ch>
	<8ec76080911281625q5d5b8824hefb14af9b23d29f0@mail.gmail.com>
	<4B11C55E.2060909@citycable.ch>
	<F11B6C18-26EC-41F8-9EEB-A614D16945AC@r-project.org>
	<4B12C417.1050308@citycable.ch>
	<65D411CD-34C3-4B89-8FF0-98C9BD7613FB@r-project.org>
	<4B13FC0F.40604@citycable.ch>
	<F60B92C3-5989-404C-8FEB-1B6002824449@r-project.org>
Message-ID: <4B140B7A.2080102@citycable.ch>

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/



[Rd] PROTECT and OCaml GC.
Guillaume Yziquel