From: Leo B. <Leo...@um...> - 2022-09-08 14:51:55
|
On Wed, Sep 07 2022, Thomas Baruchel <bar...@gm...> wrote: > Thank you to all of you. It now works as expected. > > Maybe a slightly different question however. Is it possible to access Maxima > as a "library" without having to start the interpreter as itself. > > I mean: currently, I have to > > * run Maxima; > * load some Lisp script containing a $main function > * run (from Maxima) the "main" function > > It works greatly, but I don't like too much the idea of having three layers: > > * Maxima interpreter at the toplevel > * Main loop and most of the work in Lisp code called from Maxima > * from time to time calling back Maxima from my Lisp code. Whatever image you dump, it will contain the Maxima repl in addition to the Maxima-Lisp repl, so this is really just about picking a convenient entry point. > > Assuming I don't want (this time) to define any function in Maxima, but only > use some core functions, I would expect the following process to work: > > * compile maxima but replace > > (sb-ext:save-lisp-and-die "binary-sbcl/maxima.core" :toplevel #'cl-user::run) > > with > > (sb-ext:save-lisp-and-die "binary-sbcl/maxima.core") > > * run sbcl with sbcl --core maxima.core --load myfile.lisp > * calling (for instance) $sqrt from within myfile.lisp > You need to declare a toplevel. This works: $ sbcl --core ./maxima.core * (sb-ext:save-lisp-and-die "maxima.core" :executable t :toplevel #'maxima::$to_lisp) [undoing binding stack and other enclosing state... done] [performing final GC... done] [defragmenting immobile space... (fin,inst,fdefn,code,sym)=594+760+24676+26625+27150... done] [saving current Lisp image into maxima.core: writing 0 bytes from the read-only space at 0x50000000 writing 736 bytes from the static space at 0x50100000 writing 38797312 bytes from the dynamic space at 0x1000000000 writing 2236416 bytes from the immobile space at 0x50200000 writing 22208512 bytes from the immobile space at 0x52a00000 done] $ ./maxima.core Type (to-maxima) to restart, ($quit) to quit Maxima. ^^^^^^^^^^Message emitted by to_lisp^^^^^^^^^^^^^^^^ COMMON-LISP-USER> (in-package :maxima) #<PACKAGE "MAXIMA"> MAXIMA> (mfuncall '$factor 35) ((MTIMES SIMP FACTORED) 5 7) MAXIMA> You can, of course, right your own repl, too. HTH, Leo |