manywaypark's Blog
개발, 검색, 함수

초기화 파일을 응용하여 명령행에서 유닉스 스크립트처럼 lisp 파일을 실행하는 법에 대해 간단히 기술한다.

초기화 파일 위치:
  1. 시스템 수준: 기본값은 SBCL_HOME/sbclrc, 없으면, /etc/sbclrc이다. 명령행에서 --sysinit로 지정가능.
  2. 사용자 수준: 기본값은 HOME/.sbclrc이지만 명령행에서 --userinit로 지정가능.
상기 초기화 파일 중에 적절한 것을 선택해서 다음의 내용을 추가한다. 파일이 없으면 만든다.

shebang(#!) 형태의 lisp 프로그램 실행을 위한 초기화 파일 내용:
;;; If the first user-processable command-line argument is a filename,
;;; disable the debugger, load the file handling shebang-line and quit.
(let ((script (and (second *posix-argv*)
(probe-file (second *posix-argv*)))))
(when script
;; Handle shebang-line
(set-dispatch-macro-character #\# #\!
(lambda (stream char arg)
(declare (ignore char arg))
(read-line stream)))
;; Disable debugger
(setf *invoke-debugger-hook*
(lambda (condition hook)
(declare (ignore hook))
;; Uncomment to get backtraces on errors
;; (sb-debug:backtrace 20)
(format *error-output* "Error: ~A~%" condition)
(quit)))
(load script)
(quit)))

test program(hello.lisp):
#!/usr/bin/sbcl --noinform
(write-line "Hello, World!")

실행:
$ chmod +x hello.lisp
$ ./hello.lisp
Hello, World!
$ sbcl hello.lisp
This is SBCL 0.9.14, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
Hello, World!

참고: http://www.sbcl.org/manual/Initialization-Files.html

2007-10-24
cl-launch를 사용하면 sbcl을 포함한 다른 CL implementation에서도 쓸 수 있는 좀 더 일반적인 방법으로 common lisp 프로그램을 명령행에서 실행할 수 있다.

happy hackin'
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-16 23:43