Lisp 中的布尔返回函数
Boolean returning functions in Lisp
有没有办法通过调用一个函数的名字来在 Lisp 中 return t 或 nil?下面的代码是不言自明的,但它不起作用,我不知道为什么。我知道还有其他方法可以达到相同的结果,但我这样做是为了找出布尔 returning 函数在 Lisp 中的工作方式。
(print "Enter any number to check if it is greater than 5.")
(defvar v (read))
(if (check v) (print "It is greater than 5") (print "It is not greater than 5"))
(defun check(x)
(if (> x 5) (t) (nil))
)
你不需要做
(if <condition> t nil)
因为 <condition>
已经 returns t
或 nil
在测试时。
也一样
(defun check (x) <condition>)
在这种情况下
(defun check (x) (> x 5))
有没有办法通过调用一个函数的名字来在 Lisp 中 return t 或 nil?下面的代码是不言自明的,但它不起作用,我不知道为什么。我知道还有其他方法可以达到相同的结果,但我这样做是为了找出布尔 returning 函数在 Lisp 中的工作方式。
(print "Enter any number to check if it is greater than 5.")
(defvar v (read))
(if (check v) (print "It is greater than 5") (print "It is not greater than 5"))
(defun check(x)
(if (> x 5) (t) (nil))
)
你不需要做
(if <condition> t nil)
因为 <condition>
已经 returns t
或 nil
在测试时。
也一样
(defun check (x) <condition>)
在这种情况下
(defun check (x) (> x 5))