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 "print" in the R command, I actually see the R output.
And with the 'P, I actually get a return value.
But what can I do in PicoLisp with that pointer? If I skip the "print" and
just call R for the return value:

rinc: (evalInR "6*4")
-> 65814160

how can I extract the result from that Pointer in PicoLisp (lack of C
skills ... ;-)?
Cheers
Thorsten

Am Di., 6. Apr. 2021 um 10:23 Uhr schrieb Alexander Burger <
a...@software-lab.de>:

> 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: logical vector
> >    - STRSXP: character vector
> >    - ... (and a dozen more)
>
> I do not really understand the implications in the context of R, but Pil21
> has a
> new 'T' result specification for raw Lisp data.
>
> It allows to pass a pointer to any Lisp data item to a native function,
> and/or
> to return such data.
>
>
> > When I have an imaginary generic C function like this:
> >
> > SEXP fun(SEXP x, char * cmd)
>
> As an example, we might call the standard 'prog1' function in the Pil21
> executable (which has the internal label "_prog1", try (vi 'prog1)). It
> takes a
> list for the body, and returns the resulting value:
>
>    : (%@ "_prog1" T '(T prog1 7 (println 1 2 3)))
>    1 2 3
>    -> 7
>
> This is equivalent to
>
>    : (prog1 7 (println 1 2 3))
>    1 2 3
>    -> 7
>
>
> > how can I specify Return Value/Arguments in a 'native' call, if I cannot
> > know in advance to which R subtype the  SEXP Points?
>
> If the above is not what you intended, the 'P' result specification can be
> used
> as an unspecific pointer (void*, an unsigned 64 bit number).
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to