练习2.46
这道题就是彻头彻尾的”构造”了。直接上代码吧。
(define (make-vect xcor ycor) (listxcor ycor))
(define (xcor-vect v) (car v))
(define (ycor-vect v) (cdr v))
(define (add-vect first-vectsecond-vect)
(make-vect (+ (xcor-vect first-vect)
(xcor-vect second-vect))
(+ (ycor-vect first-vect)
(ycor-vect second-vect))))
(define (sub-vect first-vectsecond-vect)
(make-vect (- (xcor-vect first-vect)
(xcor-vect second-vect))
(- (ycor-vect first-vect)
(ycor-vect second-vect))))
(define (scale-vect vect factor)
(make-vect (* (xcor-vect vect) factor)
(* (ycor-vect vect) factor)))
时间: 2024-11-09 06:20:55