"SICP Exercise" 150 Exercise 4.6

Source: Internet
Author: User

Exercise 4-6 Original

Exercise 4.6. Let expressions is derived expressions, because
(Let () ... ( )) )
is equivalent to
((Lambda (...)))
Implement a syntactic transformation let->combination that reduces evaluating let expressions to evaluating combination S of the type shown above, and add the appropriate clause to eval-handle let expressions.

Analysis

This problem requires that we convert let expressions into corresponding expressions.

(Let () ... ( )) )

From the above example we can see that in the let expression, it is assumed that it is expr, which can be obtained with CDR (() ... ()), and then use the high-order function map with car to remove all var.

Similarly, if you want to take out the exp part, use CADR first, then use the higher order function map with Cadr.

And the body part with CADDR can directly find out.

You can then start writing let->combination, which passes in a parameter expr.

((Lambda (...)))

According to this example code, we first call the No. 256 page of the book Make-lambda to construct the previous one, the function has two parameters parameter and body.

This will all be done, of course, and you will need to add the let to eval, before you define the lets. Also to invoke the No. 256 page of tagged-list?. So the next step is the specific code.

Code
(define (let-vars expr ) (map car (cadr expr))) (define (let-exp expr) (map cadr (cadr expr) ))(define (let-body expr ) (caddr expr))(define (let->combination expr)(cons (make-lambda ( let-vars expr ) ( let-body expr))(let-exp Expr       )))(define (let. expr) (tagged-list expr ' let))(Let expr ) (eval (let->combination expr) env)) 

"SICP Exercise" 150 Exercise 4.6

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.