Skip to content

PROTECT and OCaml GC.

3 messages · Guillaume Yziquel, Romain Francois

#
Simon Urbanek a ?crit :
Hi.

Concerning tryEval, I had a look at context.c, and it says:
Now, here's a feature I'd like to implement with the API:

In OCaml, there's a library called Lwt. It's a library implementing 
lightweight, or green, threads. The idea is the following:

Suppose I have to evaluate f (). I do:

let lwt_f = Lwt.return (f ()).

Now, I want to evaluate g (f ()). I write:

let lwt_g = lwt_f >>= (function x -> Lwt.return (g x)).

This might seem overly complicated, and it somehow is. The interesting 
point is this ">>=" operator. Because it allows to compose two (or more) 
computations, and it does context commutations.

So this implements threads in a cooperative way, all running in one 
single real thread.

What I want to do is to be able to launch some R code, and have it 
multithread with other OCaml code, within one single real thread. 
Therefore I have to implement the commutation context somewhere in the 
evaluation mechanism of R itself.

The API doesn't support that, I guess.
#
Guillaume Yziquel a ?crit :
And concerning tryEval, there's one feature I miss: there is error 
handling capabilities, but to my knowledge, it provides a boolean status 
back. True or false. Is it possible to get a full error message back, so 
that it can be analysed and translated to OCaml exceptions?

  
    
#
On 01/09/2010 02:04 AM, Guillaume Yziquel wrote:
Not to my knowledge, what we do in Rcpp is to to bring the expression to 
the R side, evaluate it within a tryCatch and then grab either the 
result if successfull, or the error.

The R side of this is in :
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/R/exceptions.R?rev=249&root=rcpp&view=markup

and the C++ class is the Evaluator class:
http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/src/Evaluator.cpp?rev=260&root=rcpp&view=markup

It smells the "it works but ..." pattern.

tryEval is just a thin wrapper around R_ToplevelExec (in context.c), 
what you need (and we need also in Rcpp) is a somewhat improved version 
of R_ToplevelExec which would modify the context. This would remove the 
need for a round trip to the R side...

I once tried to factor R_ToplevelExec out of R into a package, but 
failed. When I get a better understanding of contexts, I might propose 
something.