理系学生日記

おまえはいつまで学生気分なのか

忍者TOOLS

問題2-46

どっかでやった問題ですね。

(define (make-vect x y)
  (cons x y))

(define (x-cor vect)
  (car vect))

(define (y-cor vect)
  (cdr vect))

(define (add-vect v1 v2)
  (make-vect 
   (+ (x-cor v1) (x-cor v2))
   (+ (y-cor v1) (y-cor v2))))

(define (sub-vect v1 v2)
  (make-vect
   (- (x-cor v1) (x-cor v2))
   (- (y-cor v1) (y-cor v2))))

(define (scale-vect s v)
  (make-vect
   (* s (x-cor v))
   (* s (y-cor v))))

(scale-vect 2 
	    (add-vect (make-vect 1 5)
		      (make-vect 3 6)))