为什么我收到消息 "control stack exhausted in common lisp"- sbcl

Why am I getting the message "control stack exhausted in common lisp"- sbcl

背景

我正在为 lambda 演算编译器开发一个通用的 lisp 方案,但我遇到了一些问题。

特别是:

代码如下:

(defun test1 (exp)
  (if (zero-p exp)
    `(,lambda-zerop ,(compile-scheme exp))
    'testdummy))

(defun zero-p (exp)
  "checks if EXP is a zero."
  (and (listp exp)
       (eq (car exp) 'zero?)))

(defvar lambda-zerop
  `(lamb (n)
     ((n (lamb () ,lambda-false))
      ,lambda-true)))

(defun compile-scheme (scheme-expression)
  "
  compiler a given SCHEME-EXPRESSION to the lambda calculus.
  "
  (cond ((integer-p scheme-expression)
         (church-numeral scheme-expression))
        ((zero-p scheme-expression)
         `(,lambda-zerop ,(compile-scheme scheme-expression)))
        ...))

当我尝试 运行

(test1 '(zero? 0))

(compile-scheme '(zero? 0))

我收到错误:

INFO: Control stack guard page unprotected
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread
#<THREAD "main thread" RUNNING {1001538103}>:
  Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.

PROCEED WITH CAUTION.

但有趣的是,当我继续使用 REPL 并执行以下操作时:

`(,lambda-zerop ,(compile-scheme 0))

我得到 (compile-scheme '(zero? 0)) 的正确答案。

总之,感谢阅读。希望你能回答这个问题。谢谢

这是堆栈溢出 (!)。您的程序以参数 (zero? 0) 一遍又一遍地递归调用函数 compile-scheme