Interface Prolog to R¶
@ brief How to call R from YAP
Define:¶
Functions:¶
1. X_API install_t install_real(void):
1. static bool REAL_Error__(int line, const char function, const char s, term_t t):
1. static size_t pos_dims(size_t R_index[], size_t ndims, size_t dims[]):
1. static void inc_dims(size_t R_index[], size_t ndims, size_t dims[]):
1. static size_t sexp_rank(SEXP sexp):
1. static int sexp_shape(SEXP sexp, size_t nd, size_t *shape):
1. static SEXP getListElement(SEXP list, const char *str):
1. static int setListElement(term_t t, SEXP s_str, SEXP sexp):
1. static int complex_term(term_t head, double valxP, double valyP):
1. static int REAL_term_type(term_t t, int context):
1. static int merge_dots(term_t t):
1. int term_to_S_el(term_t t, int objtype, size_t index, SEXP ans):
1. static int sexp_to_S_el(SEXP sin, size_t index, SEXP ans):
1. static int set_listEl_to_sexp(term_t t, SEXP sexp):
1. static SEXP list_to_sexp(term_t t0, int objtype):
1. static int slot_to_sexp(term_t t, SEXP *ansP):
1. static int set_slot_to_sexp(term_t t, SEXP sexp):
1. static int listEl_to_sexp(term_t t, SEXP *ansP):
1. static SEXP pl_to_func(term_t t, bool eval):
1. static int pl_to_body(term_t t, SEXP *ansP):
1. static int pl_to_defun(term_t t, SEXP *ansP):
1. static int old_list_to_sexp(term_t t, SEXP c_R, int n, bool eval):
1. static SEXP subset_to_sexp(term_t t, bool eval):
1. static int set_subset_eval(SEXP symbol, term_t a, SEXP lhs_R, SEXP sexp):
1. static int set_subset_to_sexp(term_t t, SEXP sexp):
1. static int pl_to_unary(const char s, term_t t, SEXP ansP):
1. static int pl_to_binary(const char s, term_t t, term_t tmp, SEXP ansP):
1. SEXP term_to_sexp(term_t t, bool eval): : term_to_sexp: convert a Prolog term to an R sexp
free variable is translated to an argument that can take any value, eg: [_,2]
corresponds to [,2]
in R selectors X ~ _
corresponds tp X ~ .
in R formulas
+'Atom' or "string" to R 'string' or CHARACTER object
real suggest using "..." notation for strings, but string
will work as well.
Prolog -atom or -"symbol" matches to R symbol
Prolog atom matches to R symbol
atoms can be evaluated
YAP supports . as an infix operator, so a.b can be converted into R's 'a.b'
integer basic type
float basic type
boolean in real is true or 'TRUE', false or 'FALSE'
X$E access a named attribute from a list (ie. an attribute)
O@S access a slot from an object
[...] selects a subset from a vector
= applied in code definition,
currently never evaluated
function call or closure
fuction definition (yes, you can write R code as a Prolog term)
(X -> Y)
if(Then, Else)
in(Cond, Expr)
while(Cond, Expr)
reepeat( Expr)
break
next
tthe Prolog term
ansPa pointer to the result SEXP
evalwhether to evaluate functions, eg, whether 2+3
should be converted to closure(+,[[2],[3]))
or to 5
.
return:
whether it succeeds or fails.
1. static int bind_sexp(term_t t, SEXP sexp):
1. bool sexp_to_pl(term_t t, SEXP s):
1. static foreign_t init_R(void):
1. static foreign_t stop_R(void):
1. static SEXP process_expression(const char *expression):
1. static foreign_t send_R_command(term_t cmd):
1. static foreign_t send_c_vector(term_t tvec, term_t tout):
1. static foreign_t rexpr_to_pl_term(term_t in, term_t out):
1. static foreign_t robj_to_pl_term(term_t name, term_t out):
1. static foreign_t set_R_variable(term_t rvar, term_t value):
1. static foreign_t execute_R/1(term_t value):
1. static foreign_t execute_R(term_t rvar, term_t value):
1. static foreign_t is_R_variable(term_t t):
Var:¶
1. functor_t FUNCTOR_bracket/1: