mirror of
https://github.com/correl/sicp.git
synced 2024-11-23 19:19:56 +00:00
Use segments in Ex2.2
This commit is contained in:
parent
4944d5ceec
commit
627767534f
1 changed files with 11 additions and 5 deletions
16
2-1.org
16
2-1.org
|
@ -113,11 +113,17 @@ layout: org
|
||||||
(define x-point car)
|
(define x-point car)
|
||||||
(define y-point cdr)
|
(define y-point cdr)
|
||||||
|
|
||||||
(define (midpoint-segment p1 p2)
|
(define make-segment cons)
|
||||||
(let ((average (lambda (x y) (/ (+ x y) 2))))
|
(define start-segment car)
|
||||||
(make-point
|
(define end-segment cdr)
|
||||||
(average (x-point p1) (x-point p2))
|
|
||||||
(average (y-point p1) (y-point p2)))))
|
(define (midpoint-segment segment)
|
||||||
|
(let ((p1 (start-segment segment))
|
||||||
|
(p2 (end-segment segment)))
|
||||||
|
(let ((average (lambda (x y) (/ (+ x y) 2))))
|
||||||
|
(make-point
|
||||||
|
(average (x-point p1) (x-point p2))
|
||||||
|
(average (y-point p1) (y-point p2))))))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Exercise 2.3:
|
** Exercise 2.3:
|
||||||
Implement a representation for rectangles in a plane. (Hint: You
|
Implement a representation for rectangles in a plane. (Hint: You
|
||||||
|
|
Loading…
Reference in a new issue