The problem seems to be known for a long time. It works when "compiled" but not
when interpreted.

https://bugs.launchpad.net/sbcl/+bug/1731556
https://bugs.launchpad.net/sbcl/+bug/992362
https://bugs.launchpad.net/sbcl/+bug/734259


Note: I added a "(in-package :cl-user)" top in your test.lsp, otherwise you are
in package "BOOT" where symbol conflicts may occur, e.g. (coerce 0 
'double-float):


                       FriCAS Computer Algebra System
                            Version: FriCAS 1.3.5
                    Timestamp: Mi, 17. Apr 2019 03:15:11
-----------------------------------------------------------------------------
   Issue )copyright to view copyright notices.
   Issue )summary for a summary of useful system commands.
   Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------

   Function declaration sixel : TexFormat -> Void has been added to
      workspace.
                                                                   Type: Void
   Function declaration quickLoad : String -> Void has been added to
      workspace.
                                                                   Type: Void
(3) -> )lisp (load "test.lsp")

Value = T
(3) -> )lisp (compile "test.lsp")

   >> System error:
   Invalid function name: "test.lsp"

(3) -> )lisp (compile testfun)

   >> System error:
   The variable TESTFUN is unbound.

(3) -> )lisp (compile 'testfun)

   >> System error:
   The function BOOT::TESTFUN is undefined.

(3) -> )lisp (compile 'cl-user::testfun)

Value = COMMON-LISP-USER::TESTFUN
(3) -> )lisp (testfun 10.0d0)

   >> System error:
   The function BOOT::TESTFUN is undefined.

(3) -> )lisp (CL-USER::testfun 10.0d0)

Value = #C(10.0 31.400000000000002)
(3) ->



This link may ALSO be helpful:
https://stackoverflow.com/questions/21353376/how-to-use-double-float

Although I find it realy ghastly interfacing C in fricas (but if, why not using
CFFI?)

>   The value
>     0.0d0
>   is not of type
>     (SB-ALIEN:ALIEN (* T))


)lisp (defun |foo| (x) x)
foo(7)$Lisp -> 7
foo(7.2)$Lisp ->  (265633114661417543270 . - 65)
foo(7.2::DoubleFloat)$Lisp ->  7.199999999999999

)lisp  (coerce 0 'double-float)
)lisp (defun mycoerce (x) (cl-user::coerce x 'double-float))





On 13.04.2021 03:03, Tobias Neumann wrote:
> I've noticed that FriCAS doesn't have a numerical implementation of polylog's 
> yet.
> So I will have to interface some C/Fortran code. For that I have constructed 
> a small
> example:
> 
> test.c:
> void testfun(double arg, double* realpart, double* imagpart)
> {
>     *realpart = 1.0 * arg;
>     *imagpart = 3.14 * arg;
>     return;
> }
> gcc -shared -o libtest.so test.c
> 
> test.lsp:
> (sb-alien:load-shared-object "./libtest.so")
> (defun testfun (arg)
>     (sb-alien:with-alien ((repart (double-float) 0.0d0) (impart (double-float)
> 0.0d0))
>         (sb-alien:alien-funcall
>           (sb-alien:extern-alien "testfun" (sb-alien:function sb-alien:void
> (double-float) (* double-float) (* double-float)))
>           arg (sb-alien:addr repart) (sb-alien:addr impart)
>          )
>         (complex repart impart)
>     )
> )
> 
> And I can successfully use that function within sbcl:
> sbcl --load "test.lsp"
> (testfun 10.0d0)
> #C(10.0d0 31.400000000000002d0)
> 
> Within FriCAS I ran ")lisp (load "test.lsp")" and it
> seems to parse/load the file successfully, but I can't directly use that
> function, i.e.  (testfun 10.0d0) within ")fin", and neither from within FriCAS
> as TESTFUN(1$DoubleFloat)$Lisp:
> 
> debugger invoked on a TYPE-ERROR in thread
> #<THREAD "main thread" RUNNING {1002410103}>:
>   The value
>     0.0d0
>   is not of type
>     (SB-ALIEN:ALIEN (* T))
>   from the function type declaration.
> 
> As it turns out, somehow I can not give it an initial value here, and I just
> have to declare it with (repart (double-float)), which is fine, but I am
> wondering why.
> 
> The final step for me is to convert the SExpression into a FriCAS
> Complex(DoubleFloat). For that I looked into the SExpression domain, and it
> seems to be easiest to instead return (list repart impart) and then have
> something like: 
> 
> testfun(xx) == 
>     res := TESTFUN(xx :: DoubleFloat)$Lisp
>     complex(float car res, float car cdr res) 
> 
> Presumably I could convert this into Complex(DoubleFloat) within the Lisp code
> directly with some SPADCALL calls? But the current way seems to be perfectly
> fine, but I am wondering if this is the right/recommended way to do it. 
> Overall
> I'm really happy how easy this turned out to be.
> 
> Thanks,
> Tobias
> 
> -- 
> You received this message because you are subscribed to the Google Groups
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email
> to fricas-devel+unsubscr...@googlegroups.com
> <mailto:fricas-devel+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/5eb8ad23-5c3e-4b0b-8810-9cccdc42d999n%40googlegroups.com
> <https://groups.google.com/d/msgid/fricas-devel/5eb8ad23-5c3e-4b0b-8810-9cccdc42d999n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/a992c6e0-2254-ecf9-a10a-1c35b1e2942a%40gmail.com.

Reply via email to