Skip to content

tail recursion for interpreter.py - #6

Open
natethern wants to merge 6 commits into
eliben:mainfrom
natethern:main
Open

natethern wants to merge 6 commits into
eliben:mainfrom
natethern:main

Conversation

@natethern

Copy link
Copy Markdown

Got the idea from
https://www.norvig.com/lispy.html
https://www.norvig.com/lispy2.html

Create long-recursion.scm in examples:

(define (odd? n)
  (if (<= n 0)
      #f
      (even? (- n 1))))
(define (even? n)
  (if (<= n 0)
      #t
      (odd? (- n 1))))
(write (even? (* 7 7 7 7 7 7 7)))

python compile_file.py long-recursion.scm && python run_compiled.py long-recursion.bobc ==> #f

python interpret_file.py long-recursion.scm will segfault before the patch
python interpret_file.py long-recursion.scm ==> #f after the patch

@natethern

Copy link
Copy Markdown
Author

Cleaned-up version of my previous request with improved comments and docstrings.

@eliben eliben left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again, this looks pretty good!

As mentioned before, I will leave this PR open for now. I have to think more whether I want to keep interpreter.py as simple as possible, leaving the optimizations to the other methods of running bobscheme (VMs, etc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants