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.

yziq...@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/

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to