XLISP > XLISP Plus  -  Previous | Next

savefun


Type:   -   defined macro (closure)
Source:   -   init.lsp

Syntax

(savefun function)
function - the name of the function or macro to be saved
returns - the file name that was created to save the function or macro

Description

The 'savefun' macro saves the specified function or macro to a file. The file will be called 'function.lsp' where 'function' is the name of the function or macro to save, given as parameter to the 'savefun' macro. The macro returns the file name that was created. An error will occur if the 'function' parameter is not a function or macro.

(defmacro savefun (fun)
  `(let* ((fname (strcat (symbol-name ',fun) ".lsp"))
          (fval (get-lambda-expression (symbol-function ',fun)))
          (fp (open fname :direction :output)))
     (cond (fp (print (cons (if (eq (car fval) 'lambda)
                                'defun
                                'defmacro)
                            (cons ',fun (cdr fval))) fp)
               (close fp)
               fname)
           (t nil))))

Note: The 'savefun' macro is not included in the standard Nyquist distribution. If you want to use it, copy the code to your 'init.lsp' file.

Examples

(defun myfoo (fee fi)  ; create a function
  (+ fee fi))

(savefun myfoo)        ; saves MYFOO to "MYFOO.lsp"
(savefun savefun)      ; saves SAVEFUN to "SAVEFUN.lsp"
(savefun 'a)           ; error: bad argument type

  Back to Top


XLISP > XLISP Plus  -  Previous | Next