1 / 4

3.4 Local Binding

3.4 Local Binding. Recall Scheme's let : > (let ((x 5) ‏ (y 6)) (+ x y)) ‏ 11 Make let look different in our defined language: --> let x = 5 y = 6 in +(x, y) ‏ 11. 3.4 Local Binding: Step 1. Syntax:

chandler
Download Presentation

3.4 Local Binding

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 3.4 Local Binding • Recall Scheme's let: • > (let ((x 5)‏ • (y 6)) • (+ x y))‏ • 11 • Make let look different in our defined language: • --> let x = 5 • y = 6 • in +(x, y)‏ • 11

  2. 3.4 Local Binding: Step 1 • Syntax: • <expression> ::= let {<identifier> = <expression>}* • in <expression> • Add some code to grammar: • (define grammar-3-4 • '((program (expression) a-program)‏ • (expression (number) lit-exp)‏ • (expression (identifier) var-exp) • . . . • (expression • ("let" (arbno identifier "=" expression) • "in" expression) • let-exp)

  3. 3.4 Local Binding: Step 2 • Add some code to datatype definition: • (define-datatype expression expression? • ... • (let-exp • (ids (list-of symbol?))‏ • (rands (list-of expression?)) • (body expression?)))‏

  4. 3.4 Local Binding: Step 3 • Add some code to eval-expression: • (define eval-expression • (lambda (exp env)‏ • (cases expression exp • ... • (let-exp (ids rands body)‏ • (let ((args (eval-rands rands env)))‏ • (eval-expression body • (extend-env ids args env))))‏

More Related