2.47

练习 2.47 下面是实现框架的两个可能的过程函数:

(define (make-frame origin edge1 edge2)
    (list origin edge1 edge2)
)

(define (make-frame origin edge1 edge2)
    (cons origin (cons edge1 edge2))
)

请为每个构造函数提供适当的选择函数,为框架做出相应的实现。


第一种

(define make-vect cons)
(define xcor-vect car)
(define ycor-vect cdr)

(define o (make-vect 1 2))
(define e1 (make-vect 2 3))
(define e2 (make-vect 4 5))

(define (make-frame origin edge1 edge2)
    (list origin edge1 edge2)
)

(define (origin-frame frame)
    (list-ref frame 0)
)

(define f (make-frame o e1 e2))
f
(origin-frame f)
(define (edge1-frame frame)
    (list-ref frame 1)
)

(edge1-frame f)
(define (edge2-frame frame)
    (list-ref frame 2)
)

(edge2-frame f )

第二种

(define (make-frame origin edge1 edge2)
    (cons origin (cons edge1 edge2))
)

(define (origin-frame frame)
    (car frame)
)

(define f (make-frame o e1 e2))
f
(origin-frame f)
(define (edge1-frame frame)
    (car (cdr frame))
)

(edge1-frame f)
(define (edge2-frame frame)
    (cdr (cdr frame))
)

(edge2-frame f )

results matching ""

    No results matching ""