shriram / smol

The SMoL (Standard Model of Languages) Family of Languages
15 stars 3 forks source link

Change smol/dyn-scope-is-bad to match Shriram's 2021 textbook #12

Closed LuKuangChen closed 2 years ago

LuKuangChen commented 2 years ago

That is, the only place where the interpreter goes crazy is to fetch environment from the calling side rather than from the place where the closure is constructed.

LuKuangChen commented 2 years ago

A test program

#lang smol/dyn-scope-is-bad
(deffun (fibber x)
  (if (< x 2)
      (if (<= x 0) 0 1)
      (+ (fibber (- x 1)) (fibber (- x 2)))))

(fibber 5)

The expected result is 5

shriram commented 2 years ago

Write these as tests, not just as "programs".

LuKuangChen commented 2 years ago

Fixed.