开发者

Lisp Recursion Not Calling Previous Functions

开发者 https://www.devze.com 2022-12-09 00:10 出处:网络
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.

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

精彩评论

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