正在加载图片...
(define x 5 (if(=x0) (set!x0.000001)) At present, what happens if you evaluate this expression in m-eval? Modify the evaluator so that ifs may lack an alternative, but if they are lacking the alternative and the test evaluates to false then the value of the if should be Show your changes to the evaluator, and turn in a demonstration of your extended evaluator working correctly Adding new special forms to Scheme Computer Exercise 3: Adding a special form We have seen that our evaluator treats any compound expression as an application of a procedure, unless that expression is a special form that has been explicitly defined to obey a different set of rules of evaluation(e define, lambda, if). We are going to add some special forms to our evaluator in the next few exercises A common loop construct in other languages is the do.. while loop It has the following syntax (do expl while test) The behavior is as follows: expl through expN are evaluated in sequence. Then return the symbol done; otherwise the loop is repeated from the start. For and test is evaluated. If test evaluates to #f then we stop executing the loop example (1et((x())) (do (set! x (cons x)) while ( (length x)3))) evaluate this to get i Value: done(define x 5) (if (= x 0) (set! x 0.000001)) At present, what happens if you evaluate this expression in m-eval? Modify the evaluator so that ifs may lack an alternative, but if they are lacking the alternative and the test evaluates to false, then the value of the if should be #f. Show your changes to the evaluator, and turn in a demonstration of your extended evaluator working correctly. Adding new special forms to Scheme Computer Exercise 3: Adding a special form. We have seen that our evaluator treats any compound expression as an application of a procedure, unless that expression is a special form that has been explicitly defined to obey a different set of rules of evaluation (e.g., define, lambda, if). We are going to add some special forms to our evaluator in the next few exercises. A common loop construct in other languages is the do...while loop. It has the following syntax: (do exp1 exp2 ... expN while test) The behavior is as follows: exp1 through expN are evaluated in sequence. Then test is evaluated. If test evaluates to #f then we stop executing the loop and return the symbol done; otherwise the loop is repeated from the start. For example, (let ((x '())) (do (set! x (cons '* x)) (write-line x) while (< (length x) 3))) ;evaluate this to get (*) (* *) (* * *) ; Value: done
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有