Lisp 在 Cond 语句中使用 And
Lisp using And in a Cond statement
在我的一个函数中正确使用 "cond" 和 "and" 时遇到了一些麻烦:
(cond (and (find 'hello actionsems)
(find 'formal actionsems))
(print "Chatterbot: Hello, how are you?")
(and (find 'hello actionsems)
(find 'informal actionsems))
(print "Chatterbot: Hey, how's it going?")
)
我被告知我是 "attempting to take unbound variable "AND”。有人能指出我在语法中哪里出错了吗?
COND
宏获取条件列表并依次计算它们。 CLHS 的实际语法是:
Syntax:
cond {clause}* => result*
clause::= (test-form form*)
Arguments and Values:
test-form---a form.
forms---an implicit progn.
results---the values of the forms in the first clause whose test-form yields true, or the primary value of the test-form if there are no forms in that clause, or else nil if no test-form yields true.
据此,您的条件评估应如下所示:
(cond ((and (find 'hello actionsems)
(find 'formal actionsems))
(print "Chatterbot: Hello, how are you?"))
((and (find 'hello actionsems)
(find 'infomal actionsems))
(print "Chatterbot: Hey, how's it going?")))
在我的一个函数中正确使用 "cond" 和 "and" 时遇到了一些麻烦:
(cond (and (find 'hello actionsems)
(find 'formal actionsems))
(print "Chatterbot: Hello, how are you?")
(and (find 'hello actionsems)
(find 'informal actionsems))
(print "Chatterbot: Hey, how's it going?")
)
我被告知我是 "attempting to take unbound variable "AND”。有人能指出我在语法中哪里出错了吗?
COND
宏获取条件列表并依次计算它们。 CLHS 的实际语法是:
Syntax:
cond {clause}* => result*
clause::= (test-form form*)
Arguments and Values:
test-form---a form.
forms---an implicit progn.
results---the values of the forms in the first clause whose test-form yields true, or the primary value of the test-form if there are no forms in that clause, or else nil if no test-form yields true.
据此,您的条件评估应如下所示:
(cond ((and (find 'hello actionsems)
(find 'formal actionsems))
(print "Chatterbot: Hello, how are you?"))
((and (find 'hello actionsems)
(find 'infomal actionsems))
(print "Chatterbot: Hey, how's it going?")))