正在加载图片...
write eval-unset !. which undoes the last set! to the variable. It returns an unspecified value (i.e. whatever you want it to). If the variable is unbound, it should generate an unbound variable error. Transformers: more than meets the eye In some cases, it is easy to think of implementing a special form in terms of more primitive expressions that are already covered by the evaluator. For example, suppose we have a simple special form, called until with the following behavior. An until expression contains a sequence of subexpressions, the first of which is a test expression. The idea is that one first evaluates the test expression -if it is true, we are done, and can simply return some value, such as the symbol done. If the test expression is not true, then we evaluate each of the remaining expressions in order and repeat the process One way to implement an until is to rewrite it in terms of more primitive Scheme expressions. For instance, (write-line x (set!x(+x1))) can be rewritten as (let (define (loop) (if(>x n) (begin (write-line x) (1oop)))) (loop)) and similarl (until test expl expn) (let (if test (begin expl• write eval-unset!, which undoes the last set! to the variable. It returns an unspecified value (i.e. whatever you want it to). If the variable is unbound, it should generate an unbound variable error. Transformers: More than meets the eye In some cases, it is easy to think of implementing a special form in terms of more primitive expressions that are already covered by the evaluator. For example, suppose we have a simple special form, called until with the following behavior. An until expression contains a sequence of subexpressions, the first of which is a test expression. The idea is that one first evaluates the test expression – if it is true, we are done, and can simply return some value, such as the symbol done. If the test expression is not true, then we evaluate each of the remaining expressions in order and repeat the process. One way to implement an until is to rewrite it in terms of more primitive Scheme expressions. For instance, (until (> x n) (write-line x) (set! x (+ x 1))) can be rewritten as (let () (define (loop) (if (> x n) 'done (begin (write-line x) (set! x (+ x 1)) (loop)))) (loop)) and similarly (until test exp1 exp2 ... expn) can be rewritten as (let () (define (loop) (if test 'done (begin exp1 exp2
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有