为什么和
运算符会返回一个值?返回值取决于什么?
当我尝试以下示例时 -
(write (and a b c d)) ; prints the greatest integer among a b c d
其中a
、b
、c
和d
为正整数,则和
code> 返回其中最大的一个。
但是当a
、b
、c
和d
其中之一为0或负数时,则取最小的返回整数。为什么会这样?
最佳答案
如 documentation 中所述:
The macro
and
evaluates each form one at a time from left to right. As soon as any form evaluates tonil
,and
returnsnil
without evaluating the remaining forms. If all forms but the last evaluate totrue
values, and returns the results produced by evaluating the last form. If no forms are supplied,(and)
returnst
.
因此返回值不取决于参数中“最大”或“最小”的值。
关于lisp - 和运算符 Lisp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33851885/