SICP/ex-5_50-52.scm

25 lines
750 B
Scheme
Raw Normal View History

2021-05-02 00:30:24 +02:00
(load "shared/util")
(load "shared/sicp-load-eceval-compiler")
(load "shared/sicp-compiler")
(display "\nex-5.50 - compile-metacircular-evaluator\n")
; Exercise 5.50. Use the compiler to compile the metacircular evaluator of
; section 4.1 and run this program using the register-machine simulator. (To
; compile more than one definition at a time, you can package the definitions
; in a begin.) The resulting interpreter will run very slowly because of the
; multiple levels of interpretation, but getting all the details to work is an
; instructive exercise.
(compile-and-go
'(begin
(define (factorial n)
(if (= n 1)
1
(* (factorial (- n 1)) n)))
(factorial 10)))
(display "\nex-5.51\n")
(display "\nex-5.52\n")