"SICP Exercise" 145 Exercise 4.1

Source: Internet
Author: User

Exercise 4-1 Original

Exercise 4.1. Notice that we cannot-whether the Metacircular evaluator evaluates operands from left to right or from right to left. Its evaluation order was inherited from the underlying lisp:if the arguments to cons in List-of-values was evaluated from Left-to-right, then list-of-values'll evaluate operands from left to right; And if the arguments to cons is evaluated from right to left, then list-ofvalues'll evaluate operands from right to Lef T.write A version of List-of-values that evaluates operands from left to right regardless of the order of evaluation in th e underlying Lisp. Also write a version of List-of-values that evaluates operands from right to left.

Analysis

As stated in the question, the order of evaluation of list-of-values is determined by the parameters of cons. Also use No-operands to judge the Exps, if True then return null. And the left and right points, in let in the order of evaluation can be determined. If it is from left to right, it should be evaluated first and then rest, and finally constructed together with cons.

Code
 (Define (list-of-values-l-to-r exps env)    (if (no-operands exps)‘()         (let    ( (first    (eval   first-operand  exps)  env) ) )   (let    (  (rest    (list-of-values-l-to-r   ( Rest-operands  exps)  env) ) )   (cons   First rest) ) ) ))  (Define (list-of-values-r-to-l exps env)    (if (no-operands exps)‘()         (let    ( (rest    (list-of-values-r-to-l   ( rest-operands  exps)  env) ) )   ( Span class= "Hljs-title" >let    (  (first    (eval   first-operand  exps)  env) ) )   ( cons   First rest) ) ) )) 

"SICP Exercise" 145 Exercise 4.1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.