Browse Source

Added REPL and executable saving functions

Samuel W. Flint 8 years ago
parent
commit
a1cf9e525b
1 changed files with 34 additions and 0 deletions
  1. 34 0
      derive.lisp

+ 34 - 0
derive.lisp

@@ -112,6 +112,40 @@ Calculate the cosecant of x"
 Calculate the secant of x"
   (/ (cos x)))
 
+(defun repl ()
+  (format t "Welcome to the automatic derivative calculator. Type quit to exit.~&~&> ")
+  (loop (progn (let ((in (read)))
+                 (cond
+                   ((eq in 'quit)
+                    (return))
+                   ((eq in 'trace)
+                    (trace derive plus/minus mult div chain power))
+                   ((eq in 'untrace)
+                    (untrace derive plus/minus mult div chain power))
+                   ((eq in nil))
+                   ((listp in)
+                    (format t "~%~a~%" (derive in)))))
+               (format t "~&> "))))
+
+#+sbcl (progn
+         (defun save-exec ()
+           #+lparallel (lparallel:end-kernel)
+           (sb-ext:save-lisp-and-die "derive"
+                                     :toplevel #'repl
+                                     :executable t
+                                     :purify t
+                                     :save-runtime-options t))
+         (export 'save-exec))
+
+#+ccl (progn
+        (defun save-exec ()
+          #+lparallel (lparallel:end-kernel)
+          (ccl:save-application "derive"
+                                :toplevel-function #'repl
+                                :prepend-kernel t
+                                :purify t))
+        (export 'save-exec))
+
 (defmacro define-equation-functions (name variable equation)
   (let ((derivative-name
          (intern (string-upcase (format nil "d/d~a-~a" variable name))))