So beautiful code

Reading time: 0 minutes and 39 seconds with 143 words. 本文总阅读量

So beautiful

(define (f x y)
(define (f-helper a b)
  (+ (* (square a))
      (* y b)
      (* a b)))
  (f-helper (+ 1 (* x y))
            (- 1 y)))

====> f(x,y)=x(1+xy)^2 + y(1-y)+(1+xy)(1-y) ==> a= 1+xy b= (1-y) f(x,y)=xa^2+yb+ab

====>Continue

(define (f x y)
  ((lambda (a b)
       (+ (* x (square a))
          (* y b)
          (* a b)))
    (+ 1 (* x y))
    (- 1 y)))

====>Use let to define the local variables

(define (f x y)
  (let ((a (+ 1 (* x y)))
         (b (- 1 y)))
       (+ (* x (square a))
          (* y b)
          (* a b))))

let is just the coat of the ((lambda (a b))

Of course we can use define

(define (f x y)
   (define a (+ 1 (* x y)))
   (define b (- 1 y))
 (+ (* x (square a))
    (* y b)
    (* a b)))

SICP_P42

Avatar
Ye Zhaoliang
Engineer of offshore wind turbine technique research

My research interests include distributed energy, wind turbine power generation technique , Computational fluid dynamic and programmable matter.

Related

本站访问量: