From: Ramakrishnan Muthukrishnan Date: Mon, 20 Sep 2010 16:50:40 +0000 (+0530) Subject: code in the messaging passing section X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/URI:LIT:krugkidfnzsc4/@@named=/index.php?a=commitdiff_plain;h=8905f914a0a2174f4984564dd857d49ada87cda4;p=sicp.git code in the messaging passing section --- diff --git a/src/sicp/ch2_4.rkt b/src/sicp/ch2_4.rkt index ed348fd..4f14ab5 100644 --- a/src/sicp/ch2_4.rkt +++ b/src/sicp/ch2_4.rkt @@ -103,4 +103,16 @@ (define (make-from-mag-ang r a) (make-from-mag-ang-polar r a)) -;;; data directed programming +;;; message passing +(define (make-from-real-imag x y) + (define (dispatch op) + (cond + [(eq? op 'real-part) x] + [(eq? op 'imag-part) y] + [(eq? op 'magnitude) + (sqrt (+ (square x) (square y)))] + [(eq? op 'angle) (atan y x)] + [else + (error "unknown op" op)])) + dispatch) +