LISP中的cond构造最常用于分支。
cond的语法为-
(cond (test1 action1) (test2 action2) ... (testn actionn))
cond - 示例
创建一个名为main.lisp的新源代码文件,并在其中键入以下代码-
(setq a 10) (cond ((> a 20) (format t "~% a is greater than 20")) (t (format t "~% value of a is ~d " a)))
单击执行按钮或键入Ctrl+E时,LISP会立即执行它,并且返回的结果为-
value of a is 10
请注意,第二个子句中的t确保在没有其他操作的情况下执行最后一个操作。