Common Lisp中提供了三种逻辑运算符:AND,OR,而不是运算符的布尔值。假定A=nil,B=5,那么
运算符描述示例
这需要任意数量的参数。该参数是从左向右计算。如果所有参数的计算结果为非零,那么最后一个参数的值返回。否则就返回nil。
这需要任意数量的参数。common lisp该参数是从左向右计算的,直到一个计算结果为非零,则此情况下返回参数值,否则返回nil。
示例
创建一个名为main.lisp一个新的源代码文件,并在其中输入如下代码:
(setq a 10) (setq b 20) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 5) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a nil) (setq b 0) (format t "~% A and B is ~a" (and a b)) (format t "~% A or B is ~a" (or a b)) (format t "~% not A is ~a" (not a)) (terpri) (setq a 10) (setq b 0) (setq c 30) (setq d 40) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 0, 30, 40 is ~a" (or a b c d)) (terpri) (setq a 10) (setq b 20) (setq c nil) (setq d 40) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (and a b c d)) (format t "~% Result of and operation on 10, 20, nil, 40 is ~a" (or a b c d))
当您单击Execute按钮,或按下Ctrl+ E,LISP立即执行它,返回的结果是:
A and B is 20 A or B is 10 not A is NIL A and B is NIL A or B is 5 not A is T A and B is NIL A or B is 0 not A is T Result of and operation on 10, 0, 30, 40 is 40 Result of and operation on 10, 0, 30, 40 is 10 Result of and operation on 10, 20, nil, 40 is NIL Result of and operation on 10, 20, nil, 40 is 10
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-26738-2.html
省的达到咱这打工