Let's write β

プログラミング中にできたことか、思ったこととか

QuickLispコマンドライン

Quicklispをコマンドラインから利用できれば便利です(?)
まぁいずれにせよ、なんとなくライブラリ管理と処理系は別にしておきたいのです
本当は処理系依存をはずしたいのですが、今はこれだけ

#!/usr/local/bin/sbcl --script
;;; The following lines added by ql:add-to-init-file:
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
                                       (user-homedir-pathname))))
  (when (probe-file quicklisp-init)
    (load quicklisp-init)))

(defun usage ()
 (princ 
"Usage: quicklisp <command>

COMMAND:
        search <word>          : search available library 
        install <library-name> : install specified library
        help                   : show this usage
"
))

(defun search-library (word)
  (loop for lib-name in
        (mapcar #'ql-dist:name
                (remove-if-not (lambda (dist)
                                 (search word (ql-dist:name dist)))
                               (ql:system-list)))
        do
        (format t "~5T~A~%" lib-name)))

(defun library-exists-p (library-name)
  (member-if (lambda (x) (string= library-name
                                  (ql-dist:name x)))
             (ql:system-list)))

(defun install-library (library-name)
  (ql:quickload library-name))

(defun main ()
  (if (<= (length *posix-argv*) 3)
    (let ((command (nth 1 *posix-argv*))
          (option  (nth 2 *posix-argv*)))
      (cond ((and (string= command "search")
                  (not (null option)))
             (search-library option))
            ((and (string= command "install")
                  (not (null option)))
             (if (library-exists-p option)
               (install-library option)
               (progn
                 (format t "Library ~A does not exists.~%" option)
                 (format t "~A found in these libraries~%" option)
                 (search-library option))))
            (t (usage))))
    (usage)))

(main)
$ ./quicklisp search inter
     cl-glfw-opengl-ingr_interlace_read
     cl-glfw-opengl-oml_interlace
     cl-glfw-opengl-sgix_igloo_interface
     cl-interpol
     cl-interpol-test
     cl-syntax-interpol
     com.informatimago.common-lisp.interactive
     interface
     ip-interfaces
     lisp-interface-library
     lisp-interface-library-test
     os-interface
     pure-interfaces
     reader-interception
     reader-interception-test
     stateful-interfaces
     time-interval
$ ./quicklisp install inter
Library inter does not exists.
inter found in these libraries
     cl-glfw-opengl-ingr_interlace_read
     cl-glfw-opengl-oml_interlace
     cl-glfw-opengl-sgix_igloo_interface
     cl-interpol
     cl-interpol-test
     cl-syntax-interpol
     com.informatimago.common-lisp.interactive
     interface
     ip-interfaces
     lisp-interface-library
     lisp-interface-library-test
     os-interface
     pure-interfaces
     reader-interception
     reader-interception-test
     stateful-interfaces
     time-interval
$ ./quicklisp install cl-interpol
To load "cl-interpol":
  Load 1 ASDF system:
    cl-interpol
; Loading "cl-interpol"
..................................................
[package cl-unicode]..............................
[package cl-unicode-names]........................
[package trivial-gray-streams]....................
[package flexi-streams]...........................
..................................................
..................................................
[package cl-interpol].....