schemeinterpreterracketplai

what steps included in the program's executing in Chapter9's first program of PLAI


In PLAI's chapter9 "Understanding Recursion", at the beginning, there is an example factorial:


(with (fac (fun (n)
                (if0 n 
                     1
                     (* n (fac (+ n -1))))))

At page 90, the author said "Before you continue reading, please pause for a moment, study the program carefully, write down the environments at each stage, step by hand through the interpreter, even run the program if you wish, to convince yourself that this error will occur. Understanding the error thoroughly will be essential to following the remainder of theis section."
But I am not sure that I can write down the steps completely, someone would like to help me write down the steps ? Thanks a lot in advance!


Solution

  • Let your interpreter print out the steps for you.

    (define (interp expr env)
      (displayln (list 'expr expr 'env env))
      (type-case CFAE/L expr