g0dzill3r / lispy

Scheme interpreter in Kotlin
0 stars 0 forks source link

Add proper support for closures #13

Closed g0dzill3r closed 1 year ago

g0dzill3r commented 1 year ago

The scope needs to be preserved for bound procedures and lambdas so that they properly evaluate expressions in their closure.

This:

(define (foo x) 
  (define (print-x) (display x) (newline))
  (let ((x (+ x 1)))
    (print-x)
  )
  (print-x)
)
(foo 123)

prints:

124
123

but should print:

123
123