正在加载图片...
convert such an expression into a cond. Show examples of your procedi evaluator and show examples of expressions being correctly evaluated converting case expressions into cond expressions. Also add this to you Computer Exercise 9: Name Capture and Static Analysis You' ll note that the implementation sketched above for the until special form has a flaw, namely that if we try to use a symbol named loop in an until loop we get into trouble. For example (define loop 3.14159) (define (many-circles n) (1et((x1)) (until(>x n) (display ( loop xx)) would transform to (define loop 3.14159 (define (many-circles n) (1et((x1)) (if(>x n) (begin (display ( loop xx)) (set! x (+ x 1)) (1oop)))) (1oop)))) which would give an error when we try to multiply loop as a numeric value This general problem is called name capture. One method to avoid this is to analyze the expression we are desugaring, and instead of calling the helper function loop we will give it a name that is not used already in the expression we're desugaring Thus we will need a procedure(names-used ) whic will analyze an expression and give us back a list of all of the symbol name which are referenced in that expression. For example (names-used-in '(until(> x n)(display ( loop xx))(set! x (+x 1)))) (>x n display loop) Having analyzed the expression to determine the names that are used, we need to compute a symbol not occurring in the list of used names. Such a symbol is usually called fresh. here is one way to compute a fresh symbol:convert such an expression into a cond. Show examples of your procedure converting case expressions into cond expressions. Also add this to your evaluator and show examples of expressions being correctly evaluated. Computer Exercise 9: Name Capture and Static Analysis You'll note that the implementation sketched above for the until special form has a flaw, namely that if we try to use a symbol named loop in an until loop, we get into trouble. For example: (define loop 3.14159) (define (many-circles n) (let ((x 1)) (until (> x n) (display (* loop x x)) (set! x (+ x 1))))) would transform to (define loop 3.14159) (define (many-circles n) (let ((x 1)) (let () (define (loop) (if (> x n) 'done (begin (display (* loop x x)) (set! x (+ x 1)) (loop)))) (loop)))) which would give an error when we try to multiply loop as a numeric value. This general problem is called 'name capture.' One method to avoid this is to analyze the expression we are desugaring, and instead of calling the helper function loop we will give it a name that is not used already in the expression we're desugaring. Thus we will need a procedure (names-used-in exp) which will analyze an expression and give us back a list of all of the symbol names which are referenced in that expression. For example (names-used-in '(until (> x n) (display (* loop x x)) (set! x (+ x 1)))) => (> x n display * loop) Having analyzed the expression to determine the names that are used, we need to compute a symbol not occurring in the list of used names. Such a symbol is usually called fresh. Here is one way to compute a fresh symbol :
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有