이 문제는 벡터를 구성하도록

짜맞추개(constructor)와 고르개(selector) 프로시저를 만드는 문제입니다.

 

 

c13

두 개밖에 없어서 cons로 만들었습니다.

 

 

참조

해럴드 애빌슨, 김재우 역, <컴퓨터 프로그램의 구조와 해석>, 인사이트, 2007, pp. 176

 

 

; answer
(define (make-vect x y) (cons x y))
(define (xcor-vect v) (car v))
(define (ycor-vect v) (cdr v))

(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))))

; execute
(define v1 (make-vect 1 2))
(define v2 (make-vect 3 4))
v1
v2
(add-vect v1 v2)
(sub-vect v1 v2)
(scale-vect 5 v1)

크리에이티브 커먼즈 라이선스
Creative Commons License

글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.

트랙백 주소 :: http://nosyu.pe.kr/trackback/1359

댓글을 달아 주세요

[로그인][오픈아이디란?]