Created
December 3, 2015 01:23
-
-
Save ruandao/2d88a34643d026f7036c to your computer and use it in GitHub Desktop.
2.75
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;#lang planet neil/sicp | |
#lang racket | |
(require (planet soegaard/sicp:2:1/sicp)) | |
(define wave einstein) | |
(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 -- MAKE-FROM-REAL-IMAG" op)))) | |
dispatch) | |
(define (apply-generic op arg) (arg op)) | |
(define (make-from-mag-ang magnitude angle) | |
(define (dispatch op) | |
(cond ((eq? op 'real-part) (* magnitude (cos angle))) | |
((eq? op 'imag-part) (* magnitude (sin angle))) | |
((eq? op 'magnitude) magnitude) | |
((eq? op 'angle) angle) | |
(else (error "Unknown op -- MAKE-FROM-MAG-ANG" op)))) | |
dispatch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment