为什么我会收到"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

最新更新