2.46 Exercise 2.46
Vectors can simply be another pair joined by cons:
(define (make-vect x y) (cons x y)) |
(define (xcor-vect v) (car v)) |
(define (ycor-vect v) (cdr v)) |
The operators add-vect, sub-vect, and scale-vect are similarly trivial:
(define (add-vect v1 v2) | (make-vect (+ (xcor-vect v1) (xcor-vect v2)) | (+ (ycor-vect v1) (ycor-vect v2)))) |
|
(define (sub-vect v1 v2) | (make-vect (- (xcor-vect v1) (xcor-vect v2)) | (- (ycor-vect v1) (ycor-vect v2)))) |
|
(define (scale-vect s v) | (make-vect (* s (xcor-vect v)) | (* s (ycor-vect v)))) |
|