false 和 true
如果一个值不是false(或nil)的,都认为是true.
symbol t 的值是true.
symbol nil 的值是false.
if语句
下面的代码打印出"true"
(if 'true (message "true"))
注意,true前面必须加单引号,否则报错:
error: (void-variable true)
解析器抱怨找不到变量true的值。单引号阻止解析器求值。
else语句
lisp没有提供else语句,但是只需要在if条件的执行语句之后另起一行,就相当于在写else语句。
(if (> 4 5) ; if-part
(message "4 falsely greater than 5!") ; then-part
(message "4 is not greater than 5!")) ; else-part
多个语句的组合
经常需要在if或者else块中调用多个语句。可以这样使用:
(progn
(list1..)
(list2...)
)