boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

29-innerdef.scm (503B)


      1 ;; Step 12e: inner (define …) inside a lambda body is rewritten into
      2 ;; letrec-shape so the definitions share scope with the trailing body.
      3 ;; A recursive inner define actually requires letrec semantics — plain
      4 ;; let* would leave `fact` unbound in its own RHS.
      5 (define f
      6   (lambda (x)
      7     (define a 1)
      8     (define b 2)
      9     (+ x a b)))
     10 (define g
     11   (lambda (n)
     12     (define fact
     13       (lambda (k) (if (< k 2) 1 (* k (fact (- k 1))))))
     14     (fact n)))
     15 (if (= (f 10) 13)
     16   (if (= (g 5) 120)
     17     42 0) 0)