-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exercise 2.75 from Chapter 2 part 4 about implementing `make-from-mag-ang` in message-passing style has been added. This solution is meant to be analogous to the `make-from-real-imag` provided in the book.
- Loading branch information
Showing
3 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns sicp.chapter-2.part-4.ex-2-75) | ||
|
||
; Exercise 2.75 | ||
; | ||
; Implement the constructor make-from-mag-ang in message-passing style. | ||
; This procedure should be analogous to the make-from-real-imag procedure given above. | ||
|
||
(defn make-from-mag-ang [r a] | ||
(fn [op] | ||
(cond | ||
(= op :real-part) (* r (Math/cos a)) | ||
(= op :imag-part) (* r (Math/sin a)) | ||
(= op :magnitude) r | ||
(= op :angle) a | ||
:else (throw (Exception. (str "Unknown op: MAKE-FROM-REAL-IMAG " op)))))) |