スクリプトの実行 - lisp-cookbook-ja/common-lisp GitHub Wiki
- コマンドラインでファイルを実行
CLISP
$ clisp filename.lisp
SBCL
$ sbcl --script filename.lisp
CMUCL
$ cmucl -load filename.lisp -eval '(quit)'
Allegro CL
$ alisp -#! filename.lisp
ECL
$ ecl -shell filename.lisp
Clozure CL
$ ccl --load filename.lisp --eval '(quit)'
以下のシェルスクリプトを使えばSBCLのように--scriptで実行できるようになる。
#!/bin/bash
ccl="/Applications/ccl/dx86cl64"
if [ "$1" = "--script" ] ; then
$ccl --load "$2" --eval '(ccl:quit)'
else
$ccl "$@"
fi
$ ccl --script filename.lisp
コマンドライン引数の取得
スクリプトからコマンドライン引数を利用したいとき、引数の取得方法が処理系によって違います。以下のような関数を利用すればポータブルなスクリプトが書けます。
(defun args ()
#+allegro (system:command-line-arguments)
#+sbcl sb-ext:*posix-argv*
#+clisp ext:*args*
#+ecl (si:command-args)
#+cmu ext:*command-line-words*
#+ccl ccl:*command-line-argument-list*
#+lispworks system:*line-arguments-list*)