Skip to content

Instantly share code, notes, and snippets.

@y2q-actionman
Last active August 27, 2022 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y2q-actionman/de1f09b9f474d96e2bb26a433a015f33 to your computer and use it in GitHub Desktop.
Save y2q-actionman/de1f09b9f474d96e2bb26a433a015f33 to your computer and use it in GitHub Desktop.
(eval-when (:compile-toplevel)) in (eval-when (:compile-toplevel))
#|
Some experiments to understand the example of CLHS eval-when explanations.
( http://clhs.lisp.se/Body/s_eval_w.htm#eval-when )
;;; #4: This always does nothing. It simply returns NIL.
(eval-when (:compile-toplevel)
(eval-when (:compile-toplevel)
(print 'foo4)))
|#
(in-package :cl-user)
(eval-when (:compile-toplevel) ; Action is 'Evaluate'
(print "compile-toplevel") ; Printed only on COMPILE-FILE.
(eval-when (:execute)
(print "execute in compile-toplevel")) ; Printed only on COMPILE-FILE.
;; The forms below are never executed.
;; Is it because they are *NOT* top level forms here?
(eval-when (:compile-toplevel)
(print "compile-toplevel in compile-toplevel")) ; never printed.
(eval-when (:compile-toplevel :load-toplevel)
(print "compile-toplevel load-toplevel in compile-toplevel"))) ; never printed.
(eval-when (:compile-toplevel :load-toplevel) ; Action is 'Process compile-time-too'
(terpri)
(print "compile-toplevel load-toplevel") ; Printed on COMPILE-FILE and LOAD the fasl.
(eval-when (:compile-toplevel :load-toplevel)
(print "compile-toplevel load-toplevel in compile-toplevel load-toplevel")) ; Printed on COMPILE-FILE and LOAD the fasl.
(eval-when (:compile-toplevel)
(print "compile-toplevel in compile-toplevel load-toplevel")) ; Printed only on COMPILE-FILE.
(eval-when (:load-toplevel)
(print "load-toplevel in compile-toplevel load-toplevel")) ; Printed only on LOAD the fasl.
(eval-when (:execute) ; Action is 'Evaluate'
(print "execute in compile-toplevel load-toplevel") ; Printed only on COMPILE-FILE.
(eval-when (:compile-toplevel :load-toplevel)
(print "compile-toplevel load-toplevel in execute in compile-toplevel load-toplevel")) ; never printed
))
;;; (load "test.lisp") does not execute any forms above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment