mirror of
https://github.com/correl/sicp.git
synced 2024-11-23 11:09:57 +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 y-point cdr)
|
||||
|
||||
(define (midpoint-segment p1 p2)
|
||||
(let ((average (lambda (x y) (/ (+ x y) 2))))
|
||||
(make-point
|
||||
(average (x-point p1) (x-point p2))
|
||||
(average (y-point p1) (y-point p2)))))
|
||||
(define make-segment cons)
|
||||
(define start-segment car)
|
||||
(define end-segment cdr)
|
||||
|
||||
(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
|
||||
** Exercise 2.3:
|
||||
Implement a representation for rectangles in a plane. (Hint: You
|
||||
|
|
Loading…
Reference in a new issue