Lisp 不会减少给定的值

Lisp 不会减少给定的值,lisp,common-lisp,Lisp,Common Lisp,我正试图得到照片中所附问题所示的结果 我得到的结果与我想要的完全相反 请帮我找出问题所在 下面是@scott回复后的更正 (defun decrementing (num) (if( = 1 num) (princ "the number has reach 1. goodbye.") (if ( = (- num 1) 10) (format t "~&")

我正试图得到照片中所附问题所示的结果

我得到的结果与我想要的完全相反

请帮我找出问题所在

下面是@scott回复后的更正

(defun decrementing (num)
         (if( = 1 num) 
                 (princ "the number has reach 1. goodbye.")
             (if ( = (- num 1) 10)
             (format t "~&") 
           (format t "the next number is ~d. ~&" (- num 1)
              ))) (decrementing (- num 1)))

我得到了解决方案,但循环永远不会结束

您将函数的递归部分放在对
格式
的调用中,这样它直到递归完成后才真正打印(因为
格式
的所有参数都必须在
格式
本身可以打印之前进行计算)


我已经设法解决了这个问题,非常感谢您的帮助

为什么
(=(-num 1)10)
会是真的?您有理由将文本粘贴为图片吗?@ScottHunter hmmm很好question@ScottHunter我编辑了上面的代码,但现在我无法结束循环。你是说这样吗?”代码(defun递减(num)(如果(=1 num)(原则“数字已达到1。再见”)(如果(-num 1)10)(格式t“~&”)(递减(-num 1)(格式t“下一个数字是~d.~&”(-num 1)))))“代码”现在只打印第9行我只打印第9行,其他都不打印
(defun decrementing (num)
         (if( = 1 num) 
                 (princ "the number has reach 1. goodbye.")
             (if ( = (- num 1) 0)
             (format t "~&") 
           (format t "the next number is ~d. ~&" (- num 1)
              ))) (if (> num 1)(decrementing (- num 1))))