if宏后面是一个TEST子句,其计算结果为t或nil。
if-的语法
(if (test-clause) (action1) (action2))
创建一个名为main.lisp的新源代码文件,并在其中键入以下代码。
(setq a 10) (if (> a 20) (format t "~% a is less than 20")) (format t "~% value of a is ~d " a)
单击执行按钮或键入Ctrl+E时,LISP会立即执行它,并且返回的结果为-
value of a is 10
if子句后面可以跟一个可选的then子句。
链接:https://www.learnfk.comhttps://www.learnfk.com/lisp/lisp-if-construct.html
来源:LearnFk无涯教程网
创建一个名为main.lisp的新源代码文件,并在其中键入以下代码。
(setq a 10) (if (> a 20) then (format t "~% a is less than 20")) (format t "~% value of a is ~d " a)
单击执行按钮或键入Ctrl+E时,LISP会立即执行它,并且返回的结果为-
a is less than 20 value of a is 10
还可以使用If子句创建If-Then-Else类型语句。
创建一个名为main.lisp的新源代码文件,并在其中键入以下代码。
(setq a 100) (if (> a 20) (format t "~% a is greater than 20") (format t "~% a is less than 20")) (format t "~% value of a is ~d " a)
单击执行按钮或键入Ctrl+E时,LISP会立即执行它,并且返回的结果为-
a is greater than 20 value of a is 100
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)