正在加载图片...
As before, add a pair of clauses to m-eval that transform or and and expressions into expressions that m-eval already knows how to evaluate. Remember that the ndividual expressions in the body of or are supposed to be evaluated at most once (or (begin (display (begin (display (begin (display 1")#t)) once and only , Value: done (and (begin (display a")(>65) (begin (display " b)(<6 5) (begin (display c)(+ 65)) Value: #f (One way to desugar or involves using le Lf. In this case there can be name capture"errors if the let variable appears in the or expression being desugared. For this problem, it is okay to assume that any variables you use in desugaring do not already appear. Note that there is a better way to desugar andand or that avoids this problem. In Exercise 9 we give you another way to fix this problem. Computer Exercise 8: Desugaring case. We have used the case expression in a number of recent projects. Remember ts form (case message ((TYPE)'do-something-if-message-is-type ((FoO)'do-something-else-if-message-is-foo (else 'do-something-further-if-nothing -matches) Remember the behavior of a case. In this example, the value of message would be compared against the symbol type. If they are eq? then the expressions in that clause are evaluated, and the value of the last one is returned as the value of the whole expression. If not, we move on to the next expression and repeat the process. If an expression has the keyword else as its first subexpression, we automatically evaluate the remaining subexpressions in this clau Extend m-eval to handle case expressions, by desugaring them into some other form, such as a cond. Be sure to create some appropriate syntax procedures for extracting parts of a case expression, as well as building the procedure toAs before, add a pair of clauses to m-eval that transform or and and expressions into expressions that m-eval already knows how to evaluate. Remember that the individual expressions in the body of or are supposed to be evaluated at most once: (or (begin (display "once ") #f) (begin (display "and ") #f) (begin (display "only ") 'done) (begin (display "adbmal") #t)) once and only ;Value: done (and (begin (display "a ") (> 6 5)) (begin (display "b ") (< 6 5)) (begin (display "c ") (+ 6 5))) a b ;Value: #f (One way to desugar or involves using let and if. In this case there can be "name capture" errors if the let variable already appears in the or expression being desugared. For this problem, it is okay to assume that any variables you use in desugaring do not already appear. Note that there is a better way to desugar and and or that avoids this problem. In Exercise 9 we give you another way to fix this problem.) Computer Exercise 8: Desugaring case. We have used the case expression in a number of recent projects. Remember its form: (case message ((TYPE) ‘do-something-if-message-is-type) ((FOO) ‘do-something-else-if-message-is-foo) (else ‘do-something-further-if-nothing-matches) Remember the behavior of a case. In this example, the value of message would be compared against the symbol type. If they are eq?, then the expressions in that clause are evaluated, and the value of the last one is returned as the value of the whole expression. If not, we move on to the next expression and repeat the process. If an expression has the keyword else as its first subexpression, we automatically evaluate the remaining subexpressions in this clause. Extend m-eval to handle case expressions, by desugaring them into some other form, such as a cond. Be sure to create some appropriate syntax procedures for extracting parts of a case expression, as well as building the procedure to
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有