sicp每日一题[2.75]

Exercise2.75

Implement the constructor make-from-mag-ang in message-passing style. This procedure should be an alogous to the make-from-real-imag procedure given above.


这道题非常简单,只要稍微修改一下 make-from-real-imag 就行了

(define (make-from-mag-ang r a)
  (define (dispatch op)
    (cond ((eq? op 'magnitude) r)
          ((eq? op 'angle) a)
          ((eq? op 'real-part) (* (r (cos a))))
          ((eq? op 'imag-part) (* (r (sin a))))
          (else (error "Unknown op: MAKE-FROM-MAG-ANG" op))))
  dispatch)
posted @ 2024-11-12 19:52  再思即可  阅读(0)  评论(0编辑  收藏  举报