正在加载图片...
(define (fresh-symbol free list<symbol>-> symbol computes a new symbol not occurring in free (fold-right symbol-append ' unused free)) The fixed code is below, with changes shown in bold (define (until->transformed exp) (let* ((test (cadr exp)) (other-exps )) (loop-name (fresh-symbol names-occurring))) (list () (list 'defi (1ist1。。p-name) (list ' i (append other-exps (list (loop))))) (1ist1。op-name)))) The procedure names-used-in computes all of the free variables in exp, returning a list of symbols. The procedure fresh-symbol then computes a new symbol not occurring in the free variables list, and that symbol is used instead of the symbol loop. We want you to fill in the definition of the procedure names-used-in, which computes the variables used in a particular expression a skeleton of the procedure is provided in the code, and you will need to add some extra cases Give some examples that directly show your implementation of names-used-in works. Also, come up with a test case for which one of your original desugarings(for and, or, case, or do. while) fails because of name capture. Then, change the appropriate desugaring so that it uses names-used-in and fresh-symbol to avoid name capture, and show that the problem is fixed by this change Exercise 10: Avoiding Name Capture(Optional Bonus Problem) As mentioned in problem 7, there is a desugaring for or which completely avoids name capture. Write up a procedure to perform this desugaring, using quote, quasiquote, unquote, and unquote-splicing where appropriate. A correct solution should be short around 6 lines of code(define (fresh-symbol free) ; list<symbol> -> symbol ; computes a new symbol not occurring in free (fold-right symbol-append 'unused free)) The fixed code is below, with changes shown in bold: (define (until->transformed exp) (let* ((test (cadr exp)) (other-exps (cddr exp)) (names-occurring (names-used-in exp)) (loop-name (fresh-symbol names-occurring))) (list 'let '() (list 'define (list loop-name) (list 'if test ''done (cons 'begin (append other-exps (list '(loop)))))) (list loop-name)))) The procedure names-used-in computes all of the free variables in exp, returning a list of symbols. The procedure fresh-symbol then computes a new symbol not occurring in the free variables list, and that symbol is used instead of the symbol loop. We want you to fill in the definition of the procedure names-used-in, which computes the variables used in a particular expression. A skeleton of the procedure is provided in the code, and you will need to add some extra cases. Give some examples that directly show your implementation of names-used-in works. Also, come up with a test case for which one of your original desugarings (for and, or, case, or do...while) fails because of name capture. Then, change the appropriate desugaring so that it uses names-used-in and fresh-symbol to avoid name capture, and show that the problem is fixed by this change. Exercise 10: Avoiding Name Capture (Optional Bonus Problem) As mentioned in problem 7, there is a desugaring for or which completely avoids name capture. Write up a procedure to perform this desugaring, using quote, quasiquote, unquote, and unquote-splicing where appropriate. A correct solution should be short, around 6 lines of code
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有