Interp-LETREC - Procedures and Scopes LET, to edit and...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style CS784(pm) Procedures and Scopes LET, PROC, and LETREC EOPL3 Chapter 3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) the PROC language ExpVal = Int + Bool + Proc DenVal = Int + Bool + Proc Expression ::= proc (Identifier) Expression proc-exp (var body) Expression ::= (Expression Expression) call-exp (rator rand) plus all of LET language 22
Background image of page 2
CS784(pm) Informal Semantics of Procedures Procedure Definition Store formal parameters and body Procedure Invocation Evaluate body in an environment that binds formals to actual argument values Interpretation of free -variables Use env. at proc. creation (static scoping) Use env. at proc. call (dynamic scoping) 33
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) Example Programs of PROC let f = proc (x) --(x,11) in (f (f 77)) (proc (f) (f (f 77)) proc (x) -(x,11)) let x = 200 in let f = proc (z) --(z,x) in let x = 100 in let g = proc (z) --(z,x) in --((f 1), (g 1)) 44
Background image of page 4
CS784(pm) additional value-of defs (value-of (proc-exp var body) ρ) = (proc-val (procedure var body ρ)) (value-of (call-exp rator rand) ρ) = (let ((proc (expval->proc (value-of rator ρ))) (arg (value-of rand ρ))) (apply-procedure proc arg)) 55
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) apply-procedure (procedure …) (apply-procedure (procedure var body ρ) val) = (value-of body [var=val]ρ ) 66
Background image of page 6
CS784(pm) Example Calc w/ Spec 1 77
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) Example Calc w/ Spec 2 88
Background image of page 8
CS784(pm) Example Calc w/ Spec 3 99
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) Example Calc w/ Spec 4 1010
Background image of page 10
CS784(pm) proc impl of Procedure (define proc? (lambda (val) (procedure? val))) (define procedure (lambda (var body env) (lambda (val) (value-of body (extend-env var val env))))) (define apply-procedure (lambda (pc val) (pc val)))
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) data str impl called closures (define-datatype proc proc? (procedure (var identifier?) (body expression?) (saved-env environment?))) (define apply-procedure (lambda (pc val) (cases proc pc 1212
Background image of page 12
CS784(pm) the data type expval is now … (define-datatype expval expval? (num-val (num number?)) (bool-val (bool boolean?)) (proc-val (proc proc?))) 1313
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) value-of: two new clauses (proc-exp (var body) (proc-val (procedure var body env))) (call-exp (rator rand) (let ( (proc (expval->proc ( value-of rator env))) (arg (value-of rand env))) (apply-procedure proc arg))) 1414
Background image of page 14
CS784(pm) LETREC Recursive Procedures All of PROC, plus Concrete: Expression :: = letrec IdentiFer  ( IdentiFer ) = Expression in Expression AST: letrec-exp (proc-name bound-var proc-body letrec-body) 1515
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS784(pm) value of a letrec expression (value-of (letrec-exp proc-name bound-var proc-body letrec-body) ρ) = (value-of letrec-body (extend-env-rec proc-name bound-var proc-body ρ)) 1616
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/02/2011 for the course CS 784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 52

Interp-LETREC - Procedures and Scopes LET, to edit and...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online