正在加载图片...
when the special form do. while is recognized, the evaluator desugar this expression into the simpler form and evaluates that Remember that in a syntactic transformation, you are converting one list structure into another(which will subsequently be evaluated). Thus, you should start with a simple do . While example, and write down what the equivalent simpler expression would be. You can probably use the same syntactic selectors as in Exercise 3. although the evaluation clause in m-eval will be different Hint: one correct solution to this problem involves desugaring a do.while loop into an expression having do .while as a sub-expression. Computer Exercise 7: Transforming boolean combinations. In scheme, and and or are special forms because all of the arguments to these forms are not necessarily evaluated. The following example exhibits this beh (define (safe-list-ref lst n) ninvalid-list-reference)) So, for example, if (list? lst) is false, then the expression (length 1st) is not evaluated, which is good. This is called 'short-circuiting: as soon as an argument to and evaluates to false we return true, without evaluating the remaining arguments; or behaves almost the same way. You already mplemented this behavior in pS9 but theres one more feature we want you to add The result of an or special form is not necessarily #t or #f, but rather the value of the first non-#f argument. For example, (or #f 3 4)=>3.)Likewise, if an and special form has no arguments which evaluate to #f, then its return value is the value of its last argument.(For example, (and 2 3 4)=>4.) You may read about this behavior in more detail in the scheme reference manualwhen the special form do...while is recognized, the evaluator desugars this expression into the simpler form and evaluates that. Remember that in a syntactic transformation, you are converting one list structure into another (which will subsequently be evaluated). Thus, you should start with a simple do...while example, and write down what the equivalent simpler expression would be. You can probably use the same syntactic selectors as in Exercise 3, although the evaluation clause in m-eval will be different. Hint: one correct solution to this problem involves desugaring a do...while loop into an expression having do...while as a sub-expression. Computer Exercise 7: Transforming boolean combinations. In scheme, and and or are special forms because all of the arguments to these forms are not necessarily evaluated. The following example exhibits this behaviour: (define (safe-list-ref lst n) (if (and (integer? n) (list? lst) (>= n 0) (< n (length lst))) (list-ref lst n) 'invalid-list-reference)) So, for example, if (list? lst) is false, then the expression (length lst) is not evaluated, which is good. This is called 'short-circuiting:' as soon as an argument to and evaluates to false we return true, without evaluating the remaining arguments; or behaves almost the same way. You already implemented this behavior in PS9, but there's one more feature we want you to add. The result of an or special form is not necessarily #t or #f, but rather the value of the first non-#f argument. (For example, (or #f 3 4) => 3.) Likewise, if an and special form has no arguments which evaluate to #f, then its return value is the value of its last argument. (For example, (and 2 3 4) => 4.) You may read about this behavior in more detail in the Scheme reference manual
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有