projects
/
sicp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
c3f6147
)
code in the messaging passing section
author
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Mon, 20 Sep 2010 16:50:40 +0000
(22:20 +0530)
committer
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Mon, 20 Sep 2010 16:50:40 +0000
(22:20 +0530)
src/sicp/ch2_4.rkt
patch
|
blob
|
history
diff --git
a/src/sicp/ch2_4.rkt
b/src/sicp/ch2_4.rkt
index ed348fd38f0256b14b9f67842f18cd228441bd63..4f14ab57693765f7676987e706da116601cd06e9 100644
(file)
--- 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)
+