Emacs Lisp 以外の Lisp では、if のelse部に複数の式が書けません(progn を用いる必要がある)が、Emacs Lisp ではelse部に複数の式が書けます(暗黙のprognが適用される)。
Common Lisp
#! /usr/bin/env -S sbcl --script
(defun xprint (x) (print x))
(defparameter x 1)
(if (= x 0)
(xprint 'zero)
(xprint 'not-zero)
;(xprint 'not-zero2)
)
;;; Welcome to the Emacs shell
;;;
;;; ~/lisp/if-else $ cd "d:/Users/javac/Documents/.repo/env/lisp/if-else/" && time "./if-else-1.lsp"
;;;
;;; NOT-ZERO 0.280 secs
;;; ~/lisp/if-else $
Common Lisp(defun xprint (x) (print x))
#! /usr/bin/env -S sbcl --script
(defun xprint (x) (print x))
(defparameter x 1)
(if (= x 0)
(xprint 'zero)
(xprint 'not-zero)
(xprint 'not-zero2)
)
;;; Welcome to the Emacs shell
;;;
;;; ~/lisp/if-else $ cd "d:/Users/javac/Documents/.repo/env/lisp/if-else/" && time "./if-else-2.lsp"
;;; Unhandled SB-KERNEL::ARG-COUNT-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
;;; {1001DC0003}>:
;;; Error while parsing arguments to DESTRUCTURING-BIND:
;;; too many elements in
;;; ((= X 0) (XPRINT 'ZERO) (XPRINT 'NOT-ZERO) (XPRINT 'NOT-ZERO2))
;;; to satisfy lambda list
;;; (TEST THEN &OPTIONAL ELSE):
;;; between 2 and 3 expected, but got 4
;;;
;;; unhandled condition in --disable-debugger mode, quitting
;;; 0.217 secs
;;; ~/lisp/if-else $
Emacs Lisp
#! /usr/bin/env -S emacs -batch -l
(load "~/xprint.el")
(setq x 1)
(if (= x 0)
(xprint 'zero)
(xprint 'not-zero)
(xprint 'not-zero2)
)
;;; Welcome to the Emacs shell
;;;
;;; ~/lisp/if-else $ cd "d:/Users/javac/Documents/.repo/env/lisp/if-else/" && time "./if-else-3.el"
;;; Loading d:/Users/javac/Documents/.repo/env/xprint.el (source)...
;;; not-zero
;;; not-zero2
;;; 0.317 secs
;;; ~/lisp/if-else $
xprint.el
については、『Emacs Lisp でプリントデバッグをする (5) - Qiita』をご覧ください。