Write chapter 4 summary
This commit is contained in:
71
README.md
71
README.md
@@ -20,16 +20,14 @@ I haven't completely solved the following exercises.
|
||||
does not work for joined queries.
|
||||
- Exercise 4.79. I did not attempt to solve this exercise because of not
|
||||
finishing the previous one, and it is the last one in the chapter.
|
||||
- Exercise 5.52. I have implemented the basic structure of a Scheme to C
|
||||
translator, but I only finished a basic proof-of-concept. Most of the
|
||||
additional work would be similar to 5.51.
|
||||
- Exercise 5.52. I have implemented the Scheme to C interpreter and it works
|
||||
for simple programs like computing factorials or Fibonacci numbers.
|
||||
|
||||
I had a great time working through this book. I feel like my mental capabilities
|
||||
improved throughout the process, and finishing all the exercises gives me an
|
||||
incredible feeling of accomplishment. I have written short summaries for each of
|
||||
the chapters below.
|
||||
|
||||
|
||||
# Chapter 1
|
||||
|
||||
The first chapter of SICP starts by explaining the Scheme syntax. The first
|
||||
@@ -190,3 +188,68 @@ example, in embedded development.
|
||||
|
||||
# Chapter 4
|
||||
|
||||
Chapter 4 introduces the concept of a metacircular evaluator. That is a Scheme
|
||||
program that interprets Scheme programs. This approach enables us to use the
|
||||
native interpreter while gradually replacing procedures with our
|
||||
implementations.
|
||||
|
||||
In particular, we can read the Scheme code with the `read` procedure without
|
||||
worrying about lexing or parsing. Calling read on a Scheme program returns a
|
||||
data representation of the program. In other words, we can think of a program as
|
||||
an abstraction for a machine.
|
||||
|
||||
Throughout the first section, we finish a first version of the metacircular
|
||||
evaluator, including implementing the environment model via frames. We then
|
||||
optimize the evaluator by adding an analyzer layer that optimizes a program for
|
||||
faster interpretation by avoiding repetitive interpretation of static data.
|
||||
|
||||
In the next section, we change the metacircular evaluator to lazy evaluation. In
|
||||
one of the book's first exercises, we learned that Scheme is an
|
||||
applicative-order language, meaning that Scheme evaluates all arguments before a
|
||||
procedure call. In contrast, lazy evaluation delays the evaluation until a
|
||||
primitive procedure requires the actual value. By making this change, we turn
|
||||
Scheme into a normal-order language.
|
||||
|
||||
Moving forward, we learn about even more exciting models for computation. In the
|
||||
next section, we implement a non-deterministic version of Scheme via the `amb`
|
||||
operator. This operator allows us to assign multiple values to a variable. The
|
||||
amb evaluator then determines valid values based on constraints given in the
|
||||
program. In the most straightforward implementation, the amb evaluator searches
|
||||
over all possible ways. That means the programmer must add conditions to
|
||||
optimize the program.
|
||||
|
||||
Here is a simple example that shows how the amb evaluator works:
|
||||
|
||||
```scheme
|
||||
]=> (list (amb 1 2 3) (amb 'a 'b))
|
||||
(1 a) (1 b) (2 a) (2 b) (3 a) (3 b)
|
||||
```
|
||||
|
||||
In the following section, we implement an interpreter for logic-based programs.
|
||||
The book introduces a database of employees in a company, and we can then query
|
||||
that database based on specific constraints. For example, to see who Ben
|
||||
Bitdiddle supervises, we could use the following query.
|
||||
|
||||
```
|
||||
(eval-query '(supervisor ?x (bitdiddle ben)))
|
||||
```
|
||||
|
||||
I have found it fascinating to learn about these alternative models for
|
||||
computation. The chapter has helped me better understand database query
|
||||
languages like SQL and the Prolog programming language that I dabbled with a
|
||||
couple of years ago. It's fascinating to see how we can add entirely different
|
||||
programming concepts to Scheme.
|
||||
|
||||
|
||||
# Chapter 5
|
||||
|
||||
|
||||
|
||||
# Resources
|
||||
|
||||
- [SICP book](https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-4.html#%_toc_start)
|
||||
- [SICP solutions](http://community.schemewiki.org/?SICP-Solutions)
|
||||
- [SICP code from book](https://mitpress.mit.edu/sites/default/files/sicp/code/index.html)
|
||||
- [Scheme specification](https://schemers.org/Documents/Standards/R5RS/r5rs.pdf)
|
||||
- [Scheme parser spec](https://amirkamil.github.io/project-scheme-parser/scheme-parser-spec.pdf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user