[Openmcl-devel] Using ccl as a #! scripting language

David Brown lisp at davidb.org
Sun Oct 26 07:36:48 PDT 2008


On Sun, Oct 26, 2008 at 12:07:06PM +0000, John McAleely wrote:

>The script below is my attempt at making this practical, that I've  
>used on 10.5 with a recent version (just before 1.2) of ccl

I like the idea of setting the arguments into a variable, although I
suspect that there are likely to be quoting issues if the arguments
have quote signs or backslashes.

I've done something similar, although I did more in lisp.  I just
invoke ccl -n -l loader.lisp

loader.lisp:
----------------------------------------------------------------------
(defun extract-args (args)
   "Extract the arguments intended for us from those necessary to start
the lisp system.  Basically, look for '--' to flag the end of
lisp-system arguments, and return those after this."
   (do ((args args (cdr args)))
       ((or (null args)
            (string= "--" (car args)))
        (cdr args))))

(ldump:main
  (extract-args
   #+ccl (ccl::command-line-arguments)
   #+sbcl sb-ext:*posix-argv*))

#+ccl (ccl:quit)
#+sbcl (sb-ext:quit)
----------------------------------------------------------------------

wrapper script:
...
    ccl64 -n -l loader.lisp -- "$@"

Unfortunately, command-line-arguments isn't exported by ccl, but the
'--' does seem to robustly stop it from trying to interpret my
arguments as intended to ccl.

># pass a little bit of read-macro magic in first,
># so that the line #!/usr... in your script is ignored.
># declares #! as a read macro that ignores the remainder of the line.
>$CCL \
>  -e "(set-dispatch-macro-character #\\# #\\!
>       #'(lambda (s c1 c2)
>           (declare (ignore c1 c2))
>           (read-line s t nil t)))" \
>  -e "$CMDLINE" \
>  -l "$SCRIPT"

You might also look at SBCL's doc on this, since they have another
hook that catches exceptions and just prints them and exits.  CCL can
do this with '-b' added to it's command, but it does print out a full
stack trace.

Also, technically, the SBCL also gets it wrong as well.  The dispatch
macro function should end in (values), otherwise, the string of the
ignored line is the result of reading the line.  It doesn't really
hurt anything in this case, though.

David



More information about the Openmcl-devel mailing list