UNB/ CS/ David Bremner/ teaching/ cs3613/ lectures/ examples/ racket/ mk-rec2.rkt
#lang plai
(require "preproc.rkt"  "fae+if0.rkt")

(define mk-rec0
  '{fun {body-proc}
        {with [outer
               {fun {myself}
                 {with [wrapper 
                        {fun {x}
                            {{myself myself} 
                             x}}]
                       {body-proc wrapper}}}]
         {outer outer}}}
)
         
(define mk-rec
  (preproc (wparse mk-rec0)))
(test 
 mk-rec 
 (parse 
  '{fun {body-proc}
        { {fun {outer} {outer outer}} 
          {fun {myself} 
               { {fun {wrapper} 
                      {body-proc wrapper}} 
                 {fun {x} 
                      {{myself myself} x}} 
                 }}}}))
(define fact
  (app mk-rec
       (parse
        '{fun 
          {fac}
          {fun {n}
               {if0 n
                    1
                    {* n 
                       {fac 
                        {+ n -1}}}}}})))
 
(interp (app fact (num 120)) (mtSub))


;;