开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜