正在加载图片...
Summary of part 3 Implementing lambda Within analyze Body stored in double bubble is an execution procedure cursively call analyze on subexpressions old make-procedure list<symbol>, expression, Env- Procedure create an execution procedure which stores the EPs for subexpressions as local state new make-procedure list<symbol, (Env->anytype), Env- Procedure proc (analyze (lambda-body exp))) (makke-procedure s bproc env))) Implementing apply: execution phase Implementing apply: analysis phase (define (execute-application proc args) (cond (define (analyze-application exp) ((primitive-procedure? proc) (let ((fproc (analyze (operator exp))) (aprocs (map analyze (operands exp)))) ((compound-procedure? proc) (lambda (env) ((procedure-body proc) (execute-application (extend-environment (parameters proc) (fproc env) (map (lambda (aproc) (aproc env)) )) Summary of part 4 What is Eval really? In the analyz Suppose you were a circuit design double bubble stores execution procedure, not Given a circuit diagram, you could transform it into an electric Now suppose you wanted to build a circuit that could take any such signal as input(any other circuit) and could then configure itself to simulate that input circuit What would this general circuit look like??? Suppose instead you describe a circuit as a program Can you build a program that takes any program as inp and reconfigures itself to simulate that input program Sure-that's just EVALll-it's a UNIVERSAL MACHINE4 19/33 Summary of part 3 • Within analyze • recursively call analyze on subexpressions • create an execution procedure which stores the EPs for subexpressions as local state 20/33 Implementing lambda • Body stored in double bubble is an execution procedure • old make-procedure list<symbol>, expression, Env → Procedure • new make-procedure list<symbol>, (Env->anytype), Env → Procedure (define (analyze-lambda exp) (let ((vars (lambda-parameters exp)) (bproc (analyze (lambda-body exp)))) (lambda (env) (make-procedure vars bproc env)))) 21/33 Implementing apply: execution phase (define (execute-application proc args) (cond ((primitive-procedure? proc) ...) ((compound-procedure? proc) ((procedure-body proc) (extend-environment (parameters proc) args (environment proc)))) (else ...))) 22/33 Implementing apply: analysis phase (define (analyze-application exp) (let ((fproc (analyze (operator exp))) (aprocs (map analyze (operands exp)))) (lambda (env) (execute-application (fproc env) (map (lambda (aproc) (aproc env)) aprocs))))) 23/33 Summary of part 4 • In the analyze evaluator, • double bubble stores execution procedure, not expression 24/33 What is Eval really? • Suppose you were a circuit designer • Given a circuit diagram, you could transform it into an electric signal encoding the layout of the diagram • Now suppose you wanted to build a circuit that could take any such signal as input (any other circuit) and could then reconfigure itself to simulate that input circuit • What would this general circuit look like??? • Suppose instead you describe a circuit as a program • Can you build a program that takes any program as input and reconfigures itself to simulate that input program? • Sure – that’s just EVAL!! – it’s a UNIVERSAL MACHINE
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有