-
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.
Add solution for Exercise 2.76 in SICP (#153)
The solution provides a detailed discussion of different strategies for adding new types or operations in a system with generic operations.
- Loading branch information
Showing
2 changed files
with
32 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns sicp.chapter-2.part-4.ex-2-76) | ||
|
||
; Exercise 2.76 | ||
; | ||
; As a large system with generic operations evolves, new types of data objects or new operations | ||
; may be needed. For each of the three strategies—generic operations with explicit dispatch, | ||
; data-directed style, and message-passing-style—describe the changes that must be made to | ||
; a system in order to add new types or new operations. Which organization would be most appropriate | ||
; for a system in which new types must often be added? Which would be most appropriate for | ||
; a system in which new operations must often be added? | ||
|
||
; Answer | ||
; | ||
; |------------------------|----------------------------------|-------------------------------------| | ||
; | Style | Adding New Types | Adding New Operations | | ||
; |------------------------|----------------------------------|-------------------------------------| | ||
; | Generic Operations | Add a new branch in each | Create a new procedure containing | | ||
; | with Explicit Dispatch | operation on the generic data | the dispatch for all types | | ||
; |------------------------|----------------------------------|-------------------------------------| | ||
; | Data-Directed Style | Add the corresponding operations | Add the operation to each type | | ||
; | | into the registry table | package and register them in table | | ||
; |------------------------|----------------------------------|-------------------------------------| | ||
; | Message-Passing Style | Implement the new type with | Add the operation into | | ||
; | | no extra effort needed | the implementation of each type | | ||
; |------------------------|----------------------------------|-------------------------------------| | ||
; | Best Suited For | Data-Directed Style and Message- | Explicit-Dispatch and Data- | | ||
; | | Passing Style: Systems with | Directed Style: Systems with | | ||
; | | frequent addition of new types | frequent addition of new operations | | ||
; |------------------------|----------------------------------|-------------------------------------| |