bobscheme
bobscheme copied to clipboard
tail recursion for interpreter.py
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
Cleaned-up version of my previous request with improved comments and docstrings.