code in the messaging passing section
authorRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 20 Sep 2010 16:50:40 +0000 (22:20 +0530)
committerRamakrishnan Muthukrishnan <vu3rdd@gmail.com>
Mon, 20 Sep 2010 16:50:40 +0000 (22:20 +0530)
src/sicp/ch2_4.rkt

index ed348fd38f0256b14b9f67842f18cd228441bd63..4f14ab57693765f7676987e706da116601cd06e9 100644 (file)
 (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)
+