sicp-ex-2.48



<< Previous exercise (2.47) | Index | Next exercise (2.49) >>


dudrenov

 ;; Exercise 2.48 
  
  
 ;; heh 
 (define make-segment cons) 
 (define start-segment car) 
 (define end-segment cdr) 
; exercise says to use vector representation

(define (make-segment start-point end-point)
  (list (make-vect 0 start-point)
        (make-vect 0 end-point)))
(define (start-segment seg)
  (car seg))
(define (end-segment seg)
  (cadr seg))

From ex2.6

> A two-dimensinal vector v running from the origin to a point can be represented as a pair consisting of an x-coordinate and a y-coordinate.

The above vector implementation has a constructor that takes a number and what I assume is a xy pair, which is probably a mistake. If the second parameter is a number than I suppose the constructor always produces xy pairs of the form (0,y)

Should be

 ;; Book said pair of x y but I like using lists where I can 
 (define (make-vect x y) 
   (list x y)) 
  
 ;; Constructor 
  
 (define (make-segment start end) 
   (list start end)) 
  
 ;; Selectors 
  
 (define (start-segment segment) 
   (car segment)) 
  
 (define (end-segment segment) 
   (cadr segment))