Lisp Recursion Not Calling Previous Functions
I'm trying to have a function compare the first argument of a passed in argument to a value, then if it is true, perform some function, then recursively call the same function.
(defun function (expression)
(cond
((equal (first expression) "+")
(progn (print "addition")
(function (rest expression))))))
For some reason, though, it is only going through it recu开发者_运维问答rsively and not printing. Thanks.
Perhaps you mean to say:
(defun function (expression)
(cond (expression
(cond (equal (first expression) "+")
(print "addition")))
(function (rest expression)))))
the original recurses only if (first expression) is "+" and also fails to do a nil-check.
精彩评论