From guillaume.yziquel at citycable.ch  Tue Dec  1 12:58:44 2009
From: guillaume.yziquel at citycable.ch (Guillaume Yziquel)
Date: Tue, 01 Dec 2009 12:58:44 +0100
Subject: [Rd] PROTECT and OCaml GC.
In-Reply-To: <4B14F496.5000001@citycable.ch>
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>
	<4B140B7A.2080102@citycable.ch>
	<0A1D8E9D-0BD6-40F7-B98C-59075CE04E49@r-project.org>
	<4B143401.4050607@citycable.ch>
	<7971A8AF-189B-4955-9E62-4E118E594792@r-project.org>
	<4B14E2FA.8000302@citycable.ch> <4B14F496.5000001@citycable.ch>
Message-ID: <4B1504F4.9040606@citycable.ch>

Guillaume Yziquel a ?crit :
> Guillaume Yziquel a ?crit :
>>
>> One last thing, concerning the use of promises. If I do install, 
>> findVar, without forcing the resulting promise, and then construct the 
>> call, I get a failure:

Replacing findfun by findvar works in this specific case. See below.

Could someone explain why findfun works while findvar doesn't? I've been 
looking at the source code in envir.c, and it isn't really clear why one 
way works while the other doesn't.

Is it possible, given a variable/function name, to determine if it 
should use findFun or findVar? This would be helpful for the polymorphic 
static typing of R values.

> yziquel at seldon:~/git/ocamlr-quantmod$ ocaml-batteries
>         Objective Caml version 3.11.1
> 
>       _________________________________
>      |       | |                       |
>     [| +     | | Batteries Included  - |
>      |_______|_|_______________________|
>       _________________________________
>      |                       | |       |
>      | -    Type '#help;;'   | |     + |]
>      |_______________________|_|_______|
> 
> 
> # #require "R.interpreter";;
> # let show = R.Pretty.t_of_sexp;;
> val show : R.sexp -> R.PrettyTypes.t = <fun>

findFun works.

> # let str = R.findfun (R.install "str");;
> val str : ('_a -> 'b) R.t = <abstr>
> # let lm = R.findvar (R.install "lm");;
> val lm : 'a R.promise = <abstr>
> # R.eval [str; lm];;
> function (formula, data, subset, weights, na.action, method = "qr", 
>     model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, 
>     contrasts = NULL, offset, ...)  
> - : R.sexp = <abstr>

findVar doesn't.

> # let str = R.findvar (R.install "str");;
> val str : 'a R.promise = <abstr>
> # R.eval [str; lm];;
> Erreur dans function (object, ...)  : 
>   function g?n?rique incorrecte dans 'UseMethod'
> Exception: Failure "OCaml-R error in r_eval_sxp C stub.".
> # 

All the best,

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



[Rd] PROTECT and OCaml GC.
Guillaume Yziquel