Skip to content

Commit

Permalink
Add solution for Exercise 2.76 in SICP (#153)
Browse files Browse the repository at this point in the history
The solution provides a detailed discussion of different strategies for adding new types or operations in a system with generic operations.
  • Loading branch information
SmetDenis authored Feb 4, 2024
1 parent cf167b1 commit ba8af8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Solving exercises from SICP with Clojure

[![Clojure CI](https://github.com/SmetDenis/Clojure-Sicp/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/SmetDenis/Clojure-Sicp/actions/workflows/main.yml)
![Progress](https://progress-bar.dev/121/?scale=356&title=Solved&width=500&suffix=)
![Progress](https://progress-bar.dev/122/?scale=356&title=Solved&width=500&suffix=)

SICP (Structure and Interpretation of Computer Programs) is the book of Harold Abelson and Gerald
Jay Sussman on basics of computer science and software engineering.
Expand Down Expand Up @@ -42,7 +42,7 @@ Jay Sussman on basics of computer science and software engineering.

### Chapter 2 - Building Abstractions with Data

![Progress](https://progress-bar.dev/75/?scale=97&title=Solved&width=500&suffix=)
![Progress](https://progress-bar.dev/76/?scale=97&title=Solved&width=500&suffix=)

* [2.1](https://sarabander.github.io/sicp/html/Chapter-2.xhtml#Chapter-2) Introduction to Data Abstraction - [Code in book](src/sicp/chapter_2/part_1/book_2_1.clj)
* [2.1.1](https://sarabander.github.io/sicp/html/2_002e1.xhtml#g_t2_002e1_002e1) Example: Arithmetic Operations for Rational Numbers - [2.1](src/sicp/chapter_2/part_1/ex_2_01.clj)
Expand All @@ -62,7 +62,7 @@ Jay Sussman on basics of computer science and software engineering.
* [2.4](https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_002e4) Multiple Representations for Abstract Data
* [2.4.1](https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_002e4_002e1) Representations for Complex Numbers
* [2.4.2](https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_002e4_002e2) Tagged data
* [2.4.3](https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_002e4_002e3) Data-Directed Programming and Additivity - [2.73](src/sicp/chapter_2/part_4/ex_2_73.clj), [2.74](src/sicp/chapter_2/part_4/ex_2_74.clj), [2.75](src/sicp/chapter_2/part_4/ex_2_75.clj)
* [2.4.3](https://sarabander.github.io/sicp/html/2_002e4.xhtml#g_t2_002e4_002e3) Data-Directed Programming and Additivity - [2.73](src/sicp/chapter_2/part_4/ex_2_73.clj), [2.74](src/sicp/chapter_2/part_4/ex_2_74.clj), [2.75](src/sicp/chapter_2/part_4/ex_2_75.clj), [2.76](src/sicp/chapter_2/part_4/ex_2_76.clj)
* 2.5 Systems with Generic Operations
* 2.5.1 Generic Arithmetic Operations
* 2.5.2 Combining Data of Different Types
Expand Down
29 changes: 29 additions & 0 deletions src/sicp/chapter_2/part_4/ex_2_76.clj
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 |
; |------------------------|----------------------------------|-------------------------------------|

0 comments on commit ba8af8c

Please sign in to comment.