L10Rec - Implementing Recursion cs784(Prasad) L10Rec 1 let...

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

View Full Document Right Arrow Icon
cs784(Prasad) L10Rec 1 Implementing Recursion
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(Prasad) L10Rec 2 let insufficient for recursion     (let ( ( fact ( lambda (n)                  (if (zero? n)  1                       ( * n ( fact  (- n 1))                                                                     )                )          ) )      (fact 6)     ) Problem : The closure to be formed must freeze the environment containing the “correct” binding for fact which is the closure itself !
Background image of page 2
cs784(Prasad) L10Rec 3 Correct” Environment : Circularity Old approach
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(Prasad) L10Rec 4 Concrete syntax   <expression>  ::=    letrec  <procdecl> *                        in    <expression>      <idlist>  ::=   ()             |  ( <identifier> { ,   <identifier>} * )    <procdecl> ::=   <identifier> <idlist> = <expression> Abstract Syntax              letrec-exp     (proc-names idss bodies letrec-body)
Background image of page 4
cs784(Prasad) L10Rec 5 Example    letrec      even(x) =  if  zero?(x)  then  1                  else  (odd sub1(x))      odd(x)  =  if  zero?(x)  then  0                  else  (even sub1(x))     in                (odd 13);
Background image of page 5

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

View Full DocumentRight Arrow Icon
L10Rec 6 Potential Approaches Delay the creation of the closure until a suitable environment has been formed. Create the environment and then change what one of its procedure binding points to. Simulate letrec using let and assignment in the object language, or alternatively, using assignment in the meta- language. Create the closure with a “ hole” and then “ install” the final environment, when available, later. Refer to EOPL (1st Ed., Chapter 7)
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

L10Rec - Implementing Recursion cs784(Prasad) L10Rec 1 let...

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

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