sicp 2.47

 

Exercise 2.47.  Here are two possible constructors for frames:

 

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

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

 

For each constructor supply the appropriate selectors to produce an implementation for frames.

 

第一种实现:

 

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

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

(define (edge1-frame frame)
  (list-ref frame 1))

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

 

第二种实现:

 

 

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

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

(define (edge1-frame frame)
  (cadr frame)

(define (edge2-frame frame)
  (caddr frame)

你可能感兴趣的:(SICP)