Square root of LISP

Source: Internet
Author: User

Combined Evaluation Rules
1. Evaluate the combined subexpressions
2. Apply the process that serves as the value of the leftmost subexpression (operator) to the corresponding actual parameter. The so-called actual parameter is the value of other subexpressions (operation objects ).

In order to evaluate a combined element, the same process must be executed for each element in the combined element. In terms of nature, this process is recursive.

 

(Define (square X) (* X) (define (average x y) (/(+ x y) 2) (define (sqrt x) (define (good-enough? Guess X) (<(ABS (-(square guess) x) 0.0001) (define (improve guess X) (average guess (/X guess ))) (define (SQRT-iter guess X) (if (good-enough? Guess X) Guess (SQRT-ITER (improve guess X) (SQRT-iter 1.0 X) (define (sqrt2 X) (define (good-enough? Guess) (<(ABS (-(square guess) x) 0.0001) (define (improve guess) (average guess (/X guess ))) (define (SQRT-iter guess) (if (good-enough? Guess) Guess (SQRT-ITER (improve guess) (SQRT-iter 1.0 ))

 

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.