正在加载图片...
Add let* to the evaluator as a special form To do this you will need to create some syntax procedures to extract out the parts of a let expression add a dispatch clause to m-eval to handle let* expressions create procedure(s)to handle the evaluation of the let*. We suggest that you use the following idea. If the let* has no clauses, then you simply need to evaluate the body in the current environment. Otherwise you need to create a new environment, extending the current one, in which the variable of the first clause is bound to the value (obtained by evaluation) of the corresponding part of the first clause. Within that environment, you need to continue the process, either binding the next variable to its value, or if there are not more variables, evaluating the body Add this special form to your evaluator. Turn in a listing of your changes, and examples of your procedures working on test cases Computer Exercise 5: As a final exercise in adding special forms directly to the evaluator, we would like to add a way for set! s to be undone. To do this, we will need a new special form unset! which is used as follows (define x 4) 4 (set! x 6) 6 (unset! x (unset! x 4 4 You'll notice that any number of set! s can be undone, and that unset ing a variable that hasn ' t been set does nothing create some syntax procedures to extract out the parts of a unset! expression dd a dispatch clause to m-eval to handle unset! expressions modify the binding abstraction to save old values when mutations occur and support the unset-binding-value! operation.Add let* to the evaluator as a special form. To do this, you will need to • create some syntax procedures to extract out the parts of a let* expression • add a dispatch clause to m-eval to handle let* expressions • create procedure(s) to handle the evaluation of the let*. We suggest that you use the following idea. If the let* has no clauses, then you simply need to evaluate the body in the current environment. Otherwise you need to create a new environment, extending the current one, in which the variable of the first clause is bound to the value (obtained by evaluation) of the corresponding part of the first clause. Within that environment, you need to continue the process, either binding the next variable to its value, or if there are not more variables, evaluating the body. Add this special form to your evaluator. Turn in a listing of your changes, and examples of your procedures working on test cases. Computer Exercise 5: As a final exercise in adding special forms directly to the evaluator, we would like to add a way for set!s to be undone. To do this, we will need a new special form, unset! which is used as follows: (define x 4) x ; 4 (set! x 5) x ; 5 (set! x 6) x ; 6 (unset! x) x ; 5 (unset! x) x ; 4 (unset! x) x ; 4 You'll notice that any number of set!s can be undone, and that unset!ing a variable that hasn't been set does nothing. • create some syntax procedures to extract out the parts of a unset! expression • add a dispatch clause to m-eval to handle unset! expressions • modify the binding abstraction to save old values when mutations occur and support the unset-binding-value! operation
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有