正在加载图片...
Placing a backquote before an expression is similar to placing an ordinary quote before the expression, except that any subexpression preceded by comma is evaluated. If a subexpression is preceded by comma at-sign, it is evaluated (and must produce a list) and the list is appended into the result bein formed. For example (define x (1 2 3) (define y '(4 5 6) (a b c,x @y 7 8) ; Value:(abc(123)45678) Note that that the evaluated subexpressions of a backquote form can be actual expressions, not just symbols. Thus until->transformed can also be defined as (define (until->trans formed exp) (1et() (if ,(cadr exp) (1oop)))) (1oop))) Adding new derived expressions to Scheme Early in the semester, we introduced the idea of "syntactic sugar, that is, the notion that some of the special forms in our language can be expressed as simple syntactic transformations of other language elements. Examples are cond, which can be implemented in terms of if; and let, which can be implemented in terms of lambda. Such expressions are also called derived expressions. Your job in this part will be to design and implement a new derived expression for Scheme Section 4.1.2 of the textbook demonstrates how to implement cond as a derived expression to evaluate a cond expression, we transform it to an equivalent if expression using the procedure cond->if; and then we evaluate the transformed expression. Let can also be implemented as a derived expression, as explained in exercise 4.6 on page 375 Computer Exercise 6: Let's desugar for a while. Implement a syntactic transformation to convert a do.while loop expression from Exercise 3 into a simpler expression. Then change your evaluator so thatPlacing a backquote before an expression is similar to placing an ordinary quote before the expression, except that any subexpression preceded by a comma is evaluated. If a subexpression is preceded by comma at-sign, it is evaluated (and must produce a list) and the list is appended into the result being formed. For example: (define x '(1 2 3)) (define y '(4 5 6)) `(a b c ,x ,@y 7 8) ;Value: (a b c (1 2 3) 4 5 6 7 8) Note that that the evaluated subexpressions of a backquote form can be actual expressions, not just symbols. Thus until->transformed can also be defined as (define (until->transformed exp) `(let () (define (loop) (if ,(cadr exp) 'done (begin ,@(cddr exp) (loop)))) (loop))) Adding new derived expressions to Scheme Early in the semester, we introduced the idea of "syntactic sugar," that is, the notion that some of the special forms in our language can be expressed as simple syntactic transformations of other language elements. Examples are cond, which can be implemented in terms of if; and let, which can be implemented in terms of lambda. Such expressions are also called derived expressions. Your job in this part will be to design and implement a new derived expression for Scheme. Section 4.1.2 of the textbook demonstrates how to implement cond as a derived expression: to evaluate a cond expression, we transform it to an equivalent if expression using the procedure cond->if; and then we evaluate the transformed expression. Let can also be implemented as a derived expression, as explained in exercise 4.6 on page 375. Computer Exercise 6: Let's desugar for a while. Implement a syntactic transformation to convert a do...while loop expression from Exercise 3 into a simpler expression. Then change your evaluator so that
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有