Lisp 为什么赢了';这个小小的口齿不清表达法不管用吗?
这是我Lisp的第一天。我正试图最终写一个if-else语句……希望在今年的某个时候。我不知道为什么这会给我一个错误Lisp 为什么赢了';这个小小的口齿不清表达法不管用吗?,lisp,Lisp,这是我Lisp的第一天。我正试图最终写一个if-else语句……希望在今年的某个时候。我不知道为什么这会给我一个错误 (cond (< 1 2) (print "hey")) (条件(
(cond (< 1 2) (print "hey"))
(条件(<12)(打印“嘿”)
为什么会崩溃?它表示变量“
cond
包含测试和子句的列表
(cond (<test> <if test is true>)
(<test2> <if test2 is true>)
...)
cond
获取测试和子句的列表
(cond (<test> <if test is true>)
(<test2> <if test2 is true>)
...)
“我根本没有得到列表”-这不是一个好迹象。“我试图最终编写一个if-else语句。”即使在您提供的代码中,看起来也不像您试图编写if-(then)-else;看来你是想写“如果那样的话”。你可能想要
(if(<12)(打印“hey”)
(对于else有一个隐式的nil
,或者(when(<12)(打印“hey”))
,这会更清楚地表明你不关心else部分,或者(cond(<12)(打印“hey”))
“我一点也不了解列表”-这不是一个好迹象。“我正试图最终编写一个if-else语句。”即使在您提供的代码中,看起来也不像您正在尝试编写if-(then)-else;看起来您正在尝试编写if-then。您可能想要(if(<12)(打印“hey”)
(对于else,它有一个隐式的nil
,或者(当(<12)(打印“hey”))
,这更清楚地表明您不关心其他部分,或者(cond(<12)(打印“hey”)
。
(cond (< 1 2) ;; if `<` is bound as a variable, return 2
(print "hey")) ;; if `print` is bound as a variable, return "hey"
(when (< 1 2) (print "hey"))