Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-08 Thread Alexander Burger
Hi Thorsten, > Question on topic 2: > given the C data type described below for an R "node", would it be somehow > possible to extract just the SEXPTYPE from a SEXP return value, i.e. > the first field of the sexpinfo_struct, that is the first struct in the > SEXPREC_HEADER, that is the first

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-08 Thread Thorsten Jolitz
Picolisp has "native" calls as an FFI to call C shared libraries from Picolisp, and build Picolisp wrapper functions on top of C functions defined in header files. A lot of programming languages allow that, there are e.g. many Python wrappers for all kinds of data science libraries. But with

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-08 Thread Cesar Rabak
So, if I understand correctly we could use the introspective power of picolisp and write a {meta?}program to produce the "library" for Pil, and then use this to call R from picolisp? -- Cesar Rabak On Thu, Apr 8, 2021 at 4:14 PM Thorsten Jolitz wrote: > Hi Alex, > after digging deeper in R

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-08 Thread Thorsten Jolitz
Hi Alex, after digging deeper in R Internals I found out that there are actually C access functions for the various subtypes of SEXP that can be wrapped with native too: rinc: (setupRinC) -> NIL rinc: (evalQuietlyInR "V <- c(1.5, 3.4, 4.2)") -> NIL rinc: (evalInR "V") -> 65007640 rinc: (REAL

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-07 Thread Alexander Burger
On Wed, Apr 07, 2021 at 07:46:20AM +0200, Alexander Burger wrote: > OK, so now we have a pointer to a structure filled by evalInR(). > ... >(struct (evalInR "6*4") ...) In fact this depends on what exactly evalInR() returns. If it returns a pointer to a dynamically allocated structure, and

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-06 Thread Alexander Burger
Hi Thorsten, > (de evalInR ("Cmd") > (native `*RinC "evalInR" 'P "Cmd")) > > ## SEXP evalInR(char * cmd); > > rinc: (evalInR "print(6*4)") > [1] 24 > -> 65814160 OK, so now we have a pointer to a structure filled by evalInR(). > rinc: (evalInR "6*4") > -> 65814160 > > how can I

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-06 Thread Thorsten Jolitz
Hi Cesar, it works both ways, and there is an old R C API and more modern C++ implementations (with C headers too) for the use case here: - call R from C(++). or better: - call R from PicoLisp via (native) C (calls) See my last answer to Alex to see that the call to R actually works. Cheers

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-06 Thread Thorsten Jolitz
Hi Alex, thanks for the hints, I tried both, T and 'P as result values , the first gives a segment fault, but the second actually works: (de evalInR ("Cmd") (native `*RinC "evalInR" 'P "Cmd")) ## SEXP evalInR(char * cmd); rinc: (evalInR "print(6*4)") [1] 24 -> 65814160 If I use

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-06 Thread Cesar Rabak
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

Re: Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-06 Thread Alexander Burger
Hi Thorsten, > 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:

Native Calls with SEXP (a variant type, with subtypes for all R’s data structures).

2021-04-05 Thread Thorsten Jolitz
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 -