Implement till 4.15
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
(else
|
||||
(error "Unknown expression type -- EVAL" exp))))
|
||||
|
||||
(define apply-in-underlying-scheme apply)
|
||||
|
||||
(define (apply procedure arguments)
|
||||
(cond ((primitive-procedure? procedure)
|
||||
(apply-primitive-procedure procedure arguments))
|
||||
@@ -232,4 +234,67 @@
|
||||
(scan (frame-variables frame)
|
||||
(frame-values frame))))
|
||||
|
||||
'evaluator-loaded
|
||||
(define (primitive-procedure-objects)
|
||||
(map (lambda (proc) (list 'primitive (cadr proc)))
|
||||
primitive-procedures))
|
||||
|
||||
(define primitive-procedures
|
||||
(list (list 'car car)
|
||||
(list 'cdr cdr)
|
||||
(list 'cons cons)
|
||||
(list 'null? null?)
|
||||
(list 'display display)
|
||||
;;<more primitives>
|
||||
))
|
||||
|
||||
(define (primitive-procedure-names)
|
||||
(map car
|
||||
primitive-procedures))
|
||||
|
||||
(define (setup-environment)
|
||||
(let ((initial-env
|
||||
(extend-environment (primitive-procedure-names)
|
||||
(primitive-procedure-objects)
|
||||
the-empty-environment)))
|
||||
(define-variable! 'true true initial-env)
|
||||
(define-variable! 'false false initial-env)
|
||||
initial-env))
|
||||
(define the-global-environment (setup-environment))
|
||||
|
||||
(define (primitive-procedure? proc)
|
||||
(tagged-list? proc 'primitive))
|
||||
|
||||
(define (primitive-implementation proc) (cadr proc))
|
||||
|
||||
(define (apply-primitive-procedure proc args)
|
||||
(apply-in-underlying-scheme
|
||||
(primitive-implementation proc) args))
|
||||
|
||||
(define input-prompt ";;; M-Eval input:")
|
||||
(define output-prompt ";;; M-Eval value:")
|
||||
|
||||
(define (driver-loop)
|
||||
(prompt-for-input input-prompt)
|
||||
(let ((input (read)))
|
||||
(let ((output (eval input the-global-environment)))
|
||||
(announce-output output-prompt)
|
||||
(user-print output)))
|
||||
(driver-loop))
|
||||
|
||||
(define (prompt-for-input string)
|
||||
(newline) (newline) (display string) (newline))
|
||||
|
||||
(define (announce-output string)
|
||||
(newline) (display string) (newline))
|
||||
|
||||
(define (user-print object)
|
||||
(if (compound-procedure? object)
|
||||
(display (list 'compound-procedure
|
||||
(procedure-parameters object)
|
||||
(procedure-body object)
|
||||
'<procedure-env>))
|
||||
(display object)))
|
||||
|
||||
(define the-global-environment (setup-environment))
|
||||
|
||||
; (driver-loop)
|
||||
|
||||
Reference in New Issue
Block a user