eval-when

よくわかってなかったので調べた。

ファイルのトップレベルに `(eval-when (SITUATION*) ...)` を書いて、色んな読み込み方をした場合に評価されるか否か。「ただの式」ってのは eval-when で包んでない場合。

--- :execute :load-toplevel :compile-toplevel ただの式
コンパイルせずに load
コンパイルしたとき
コンパイル済みを load

こんなファイルを用意して

;;; test-eval-when.l
(eval-when (:load-toplevel)
  (format t ":load-toplevel~%"))

(eval-when (:compile-toplevel)
  (format t ":compile-toplevel~%"))

(eval-when (:execute)
  (format t ":execute~%"))

(format t "normal toplevel form")

そんで *scratch* から

(load "~/work/xyzzy.sandbox/test-eval-when.l")
:execute
normal toplevel form
=> t

(compile-file "~/work/xyzzy.sandbox/test-eval-when.l")
:compile-toplevel
done.
=> t

(load "~/work/xyzzy.sandbox/test-eval-when.lc")
:load-toplevel
normal toplevel form
=> t