当前位置: 首页 > 文档资料 > LISP 中文教程 >

when

优质
小牛编辑
132浏览
2023-12-01

when宏后跟一个计算为t或nil的test子句。 如果test子句被计算为nil,则不评估任何形式并返回nil,但是测试结果是t,然后执行test子句之后的操作。

宏时的语法 -

(when (test-clause) (<action<sub>1</sub>) )

例子 (Example)

创建一个名为main.lisp的新源代码文件,并在其中键入以下代码。

(setq a 100)
(when (> a 20)
   (format t "~% a is greater than 20"))
(format t "~% value of a is ~d " a)

单击“执行”按钮或键入Ctrl + E时,LISP立即执行它,返回的结果为 -

a is greater than 20
value of a is 100