Function: macroexp-if
macroexp-if is a byte-compiled function defined in macroexp.el.gz.
Signature
(macroexp-if TEST THEN ELSE)
Documentation
Return an expression equivalent to `(if ,TEST ,THEN ,ELSE).
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/macroexp.el.gz
(defun macroexp-if (test then else)
"Return an expression equivalent to \\=`(if ,TEST ,THEN ,ELSE)."
(cond
((eq (car-safe else) 'if)
(cond
;; Drop this optimization: It's unsafe (it assumes that `test' is
;; pure, or at least idempotent), and it's not used even a single
;; time while compiling Emacs's sources.
;;((equal test (nth 1 else))
;; ;; Doing a test a second time: get rid of the redundancy.
;; (message "macroexp-if: sharing 'test' %S" test)
;; `(if ,test ,then ,@(nthcdr 3 else)))
((equal then (nth 2 else))
;; (message "macroexp-if: sharing 'then' %S" then)
`(if (or ,test ,(nth 1 else)) ,then ,@(nthcdr 3 else)))
((equal (macroexp-unprogn then) (nthcdr 3 else))
;; (message "macroexp-if: sharing 'then' with not %S" then)
`(if (or ,test (not ,(nth 1 else)))
,then ,@(macroexp-unprogn (nth 2 else))))
(t
`(cond (,test ,@(macroexp-unprogn then))
(,(nth 1 else) ,@(macroexp-unprogn (nth 2 else)))
,@(let ((def (nthcdr 3 else))) (if def `((t ,@def))))))))
((eq (car-safe else) 'cond)
`(cond (,test ,@(macroexp-unprogn then)) ,@(cdr else)))
;; Invert the test if that lets us reduce the depth of the tree.
((memq (car-safe then) '(if cond)) (macroexp-if `(not ,test) else then))
(t `(if ,test ,then ,@(if else (macroexp-unprogn else))))))