Hi Thorsten, The quote you copied here (coming from the ref. of yours R's C Interface), describes IIUC a structure, more accurately the model of, for calling "foreing" C functions in R and not the converse.
The way to call R functions in picolisp would be to call the functions made available through the API, in case of R a process similar to FFI using as reference the include files, wouldn't? HTH -- Cesar Rabak On Mon, Apr 5, 2021 at 4:30 PM Thorsten Jolitz <tjol...@gmail.com> wrote: > Hello List, > I wonder how to deal with the R SEXP Data structure in native calls. > > *"Technically, [a SEXP] is a pointer to a structure with typedef SEXPREC. > A SEXP is a variant type, with subtypes for all R’s data structures."* > > E.g. > > - INTSXP: integer vector > - LGLSXP: logical vector > - STRSXP: character vector > - ... (and a dozen more) > > When I have an imaginary generic C function like this: > > SEXP fun(SEXP x, char * cmd) > > how can I specify Return Value/Arguments in a 'native' call, if I cannot > know in advance to which R subtype the SEXP Points? > > On the one hand, a SEXP is like a C Datatype for a Lisp list, so one could > think that's ideal for calling C from Pil with list args and list return > values. On the other hand, how can one give the primitive specifications in > the specification lists for 'native' args/return vals, without knowing the > concrete subtype (R data structure), i.e. when CMD can be any R command > that may take/return any of the subtypes (char, logical, int, vector, list > .....)? > > Is there maybe a generic solution on the 'native' side too, without the > primitive specifications? > Thanks in advance and Cheers > Thorsten > > PS > For those interested here two links: > Rinternals.h source code: > r-source/Rinternals.h at a1425adea54bcc98eef86081522b5dbb3e149cdc · > wch/r-source (github.com) > <https://github.com/wch/r-source/blob/a1425adea54bcc98eef86081522b5dbb3e149cdc/src/include/Rinternals.h> > > R's C Interface (blog post explaining the code/data structures) > R's C interface · Advanced R. (had.co.nz) > <http://adv-r.had.co.nz/C-interface.html>. >