Elisp 逻辑运算
and
、 or
、 not
。
or
经常用于设置函数的缺省值,而 and
常用于参数检查:
(defun hello-world (&optional name) (or name (setq name "Emacser")) (message "Hello, %s" name)) ; => hello-world (hello-world) ; => "Hello, Emacser" (hello-world "Ye") ; => "Hello, Ye" (defun square-number-p (n) (and (>= n 0) (= (/ n (sqrt n)) (sqrt n)))) (square-number-p -1) ; => nil (square-number-p 25) ; => t