login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Waldek Hebisch helped me to write the following Lisp code to call the SPAD compiler from the FriCAS/AXIOM interpreter.

fricas
(1) -> )set output algebra on
 
fricas
)set output tex off

This function can be called from the interpreter to compile a SPAD program. The program source is passed as a List of Strings which is sent to the compiler as a text stream. Several flags and parameters must be set and dynamical loading of the compiler itself must be performed before calling the compiler. The parameter nil instructs the compiler to read form standard input, which in turn has been re-directed to the text stream.

This code can be compiled as below or executed directly in the interpreter via )lisp ....

lisp
(defun string2spad (the-string-list)
  (let* ( ($LISPLIB t) (|$QuickLet| t)
          (|$QuickCode| t)
          (|$InteractiveMode| nil)
          (*standard-input* (make-string-input-stream
            (format nil "~{~A~^~%~}" the-string-list))) )
  (declare (special $LISPLIB |$InteractiveMode|))
    (|oldCompilerAutoloadOnceTrigger|) (|spadCompile| nil) ))
lisp
   Your user access level is compiler and this command is therefore not
      available. See the )set userlevel command for more information.

For example:

fricas
S:=[")abbrev domain XXX xxx",
    "xxx():BasicType == Integer"]
(1) [")abbrev domain XXX xxx", "xxx():BasicType == Integer"]
Type: List(String)

fricas
STRING2SPAD(S)$Lisp
STRING2SPAD is not a lisp function and so cannot be used with $Lisp.

The output is sent to the console but the text stream can be captured as a string and returned to the caller as follows:

lisp
(defun string2spad (the-string-list)
  (let* ( ($LISPLIB t) (|$QuickLet| t)
        (|$QuickCode| t)
        (|$InteractiveMode| nil)
        (*standard-input* (make-string-input-stream
          (format nil "~{~A~^~%~}" the-string-list)))
        (*standard-output* (make-string-output-stream)) )
  (declare (special $LISPLIB |$InteractiveMode|))
  (|spadCompile| nil) (get-output-stream-string *standard-output* ) ))
lisp
   Your user access level is compiler and this command is therefore not
      available. See the )set userlevel command for more information.

and we can get the result as a string

fricas
result:=string STRING2SPAD(S)$Lisp
STRING2SPAD is not a lisp function and so cannot be used with $Lisp.




  Subject:   Be Bold !!
  ( 15 subscribers )  
Please rate this page: