[Openmcl-devel] Using OpenMCL as a shell scripting interpreter
frank.sonnemans at unitekeapro.com
Wed Mar 31 11:06:41 EST 2004
I had a similar request to use openmcl for shell scripts several
months ago. The idea was to use something like:
openmcl scriptfile args
In which openmcl would call a main function like in C. Gary send me the
following code which I dumped into an image.
;---- file "filter-app.lisp"
(in-package "CCL") ; Too many of these things are internal symbols in CCL.
;;; A FILTER-APP inherits from APPLICATION, but not from
(defclass filter-app (application) ())
;;; We'll handle the argument list by hand. It may not even be necessary
;;; to specialize this method, but it can't hurt.
(defmethod parse-application-arguments ((app filter-app))
(values nil nil nil))
;;; We don't have any sort of specialized init file.
(defmethod application-init-file ((app filter-app))
;;; All unhandled errors are fatal: we don't want to see a break loop.
(defmethod application-error ((app filter-app) cond frame)
(declare (ignore frame))
(format t "~&Fatal error: ~a~&" cond)
(force-output) ; ensure user sees the error
;;; Define the application class's toplevel function.
(defmethod toplevel-function ((app filter-app) init-file)
(declare (ignore init-file))
;; The CAR of CCL::*COMMAND-LINE-ARGUMENT-LIST* is the
;; pathname of the kernel.
;; Assume that the CADR is the name of a loadable file
;; which defines CL-USER::MAIN. After loading the
;; file, try to call CL-USER::MAIN on the CDDR of the
(load (cadr ccl::*command-line-argument-list*))
(apply #'cl-user::main (cddr ccl::*command-line-argument-list*)))
;---- end of filter-app.lisp
I call openmcl with the appropriate image using a script:
openmcl -I ~/bin/filter-app.image "$@"
# end of script
And a simple test file:
(defun print-arguments (lst)
(when (consp lst)
(format t "~%~a" (car lst))
(print-arguments (rest lst))))
(defun main (&rest arguments)
(format t "Testing filter mode openmcl")
(format t "~%All done~%~%")
Works very well.
More information about the Openmcl-devel