Reputation: 159
I am working on a common lisp scheme to lambda calculus compiler and I am having some issues.
In particular:
Here is code:
(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)))
...))
When I try to run
(test1 '(zero? 0))
or
(compile-scheme '(zero? 0))
I get the error:
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.
But interestingly when I go on the REPL and do:
`(,lambda-zerop ,(compile-scheme 0))
I get the correct solution to (compile-scheme '(zero? 0))
.
Anyways, thanks for reading. hopefully you can answer the question. thanks
Upvotes: 0
Views: 405
Reputation: 139401
It's a stack overflow (!). Your program calls the function compile-scheme
with the argument (zero? 0)
recursively over and over.
Upvotes: 2