PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, June 26, 2022

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

 June 26, 2022     common-lisp, compiler-errors, sbcl     No comments   

Issue

Background

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


Solution

It's a stack overflow (!). Your program calls the function compile-scheme with the argument (zero? 0) recursively over and over.



Answered By - Rainer Joswig
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing