This commit is contained in:
2021-04-25 08:57:17 -04:00
parent 1fdb733d0c
commit 335d011db8
62 changed files with 88 additions and 81 deletions

View File

@ -86,7 +86,7 @@ with different transformations to create more complex images. The book does not
present a way to paint to the screen, so I have implemented the painter to
create a Python script that can then draw the images via the PIL library.
![Corner Split](misc/corner-split-3.png)
![Corner Split](shared/draw-corner-split-3.png)
The next section introduces symbolic data that we utilize to implement a system
for symbolic differentiation. One of my favorite things about the book is that

View File

@ -1,4 +1,7 @@
(display "ex-1.1 - solutions in comments\n")
(display "ex-1.1 - basic-operations\n")
(display "[see comments]\n")
; 10 -> 10
; (+ 5 3 4) -> 12
; (- 9 1) -> 8
@ -18,6 +21,7 @@
; (else -1))
; (+ a 1)) ->
(display "\nex-1.2 - ")
(display (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5)))))
(* 3 (- 6 2) (- 2 7))))

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "ex-1.29") (newline)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(define (add-rat x y)
(make-rat (+ (* (numer x) (denom y))

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "ex-2.17\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-2.24\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-2.33 - list operations in terms of accumulate\n")

View File

@ -192,9 +192,9 @@
(make-line 0.6 0.65 0.65 0.8)
(make-line 0.65 0.8 0.6 1.0))))
(load "misc/draw.scm")
(load "shared/lib-draw.scm")
(draw-to-py (painter-diamond simple-frame) "wave")
(draw-to-py (painter-diamond simple-frame) "draw-wave")
(display "\nex-2.50\n")
@ -213,7 +213,7 @@
(make-vect 1.0 1.0) ; new end of edge1
(make-vect 0.0 0.0))) ; new end of edge2
(draw-to-py ((flip-vert painter-wave) simple-frame) "wave-flipped")
(draw-to-py ((flip-vert painter-wave) simple-frame) "draw-wave-flipped")
(define (shrink-to-upper-right painter)
(transform-painter painter
@ -221,7 +221,7 @@
(make-vect 1.0 0.5)
(make-vect 0.5 1.0)))
(draw-to-py ((shrink-to-upper-right painter-wave) simple-frame) "wave-shrinked")
(draw-to-py ((shrink-to-upper-right painter-wave) simple-frame) "draw-wave-shrinked")
(define (rotate90 painter)
(transform-painter painter
@ -229,7 +229,7 @@
(make-vect 1.0 1.0)
(make-vect 0.0 0.0)))
(draw-to-py ((rotate90 painter-wave) simple-frame) "wave-rotated")
(draw-to-py ((rotate90 painter-wave) simple-frame) "draw-wave-rotated")
(define (flip-horiz painter)
(transform-painter painter
@ -253,22 +253,21 @@
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))
(draw-to-py ((beside painter-wave painter-diamond) simple-frame) "wave-beside-diamond")
(draw-to-py ((beside painter-wave painter-diamond) simple-frame) "draw-wave-beside-diamond")
(display "\nex-2.51\n")
; First implementation is at the beginning of this file.
(draw-to-py ((below painter-x painter-diamond) simple-frame) "x-below-diamond-1")
(draw-to-py ((below painter-x painter-diamond) simple-frame) "draw-x-below-diamond-1")
(define (below painter1 painter2)
(rotate270 (beside (rotate90 painter2) (rotate90 painter1))))
(draw-to-py ((below painter-x painter-diamond) simple-frame) "x-below-diamond-2")
(draw-to-py ((below painter-x painter-diamond) simple-frame) "draw-x-below-diamond-2")
(display "\nex-2.52\n")
; a.
(define painter-wave-smile
(segments->painter
@ -296,7 +295,7 @@
(make-line 0.6 0.65 0.65 0.8)
(make-line 0.65 0.8 0.6 1.0))))
(draw-to-py (painter-wave-smile simple-frame) "wave-smile")
(draw-to-py (painter-wave-smile simple-frame) "draw-wave-smile")
; b.
(define (corner-split-adapted painter n)
@ -310,7 +309,7 @@
(beside (below painter top-left)
(below bottom-right corner))))))
(draw-to-py ((corner-split-adapted painter-wave 3) simple-frame) "corner-split-3")
(draw-to-py ((corner-split-adapted painter-wave 3) simple-frame) "draw-corner-split-3")
; c. didn't do anything here
(define (square-of-four tl tr bl br)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(define (memq item x)
(cond ((null? x) false)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "example - set via unordered list\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "example - Huffman Encoding Trees") (newline)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(newline) (display "ex-2.73 - deriv data-directed") (newline)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nexample - generic arithmetic operations\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-3.1 - accumulator\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-3.9 - draw factorial evaluation model\n")
(display "[see comments]\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-3.12 - append!\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nexample - queue\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "example - tables\n")

View File

@ -1,6 +1,6 @@
(load "util.scm")
(load "misc/agenda.scm")
(load "misc/queue.scm")
(load "shared/util.scm")
(load "shared/lib-agenda.scm")
(load "shared/lib-queue.scm")
(display "\nexample - simulator of digital circuits\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nexample - propagation of constraints\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(define (make-serializer)
(let ((mutex (make-mutex)))

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(display "\nex-3.50 - stream-map\n")

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(define (pi-summands n)
(cons-stream (/ 1. n)

View File

@ -1,4 +1,4 @@
(load "util.scm")
(load "shared/util.scm")
(define (integral integrand initial-value dt)
(define int

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/evaluator.scm")
(load "shared/util.scm")
(load "shared/sicp-evaluator.scm")
(display "\nex-4.1 - list-of-values\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/evaluator.scm")
(load "shared/util.scm")
(load "shared/sicp-evaluator.scm")
(display "\nex-4.11 - alternative-frame-implementation\n")

View File

@ -1,4 +1,4 @@
(load "misc/evaluator.scm")
(load "shared/sicp-evaluator.scm")
(display "\nex-4.22 - let\n")
(display "[answered]\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/evaluator.scm")
(load "shared/util.scm")
(load "shared/sicp-evaluator.scm")
(display "\nex-4.25 - factorial-unless\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/evaluator.scm")
(load "shared/util.scm")
(load "shared/sicp-evaluator.scm")
(display "\nex-4.31 - explicit-laziness\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/amb.scm")
(load "shared/util.scm")
(load "shared/lib-amb.scm")
(define (require p)
(if (not p) (amb)))

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-ambeval.scm")
(load "shared/util.scm")
(load "shared/sicp-ambeval.scm")
(define the-global-environment (setup-environment))
(define result '())

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-query.scm")
(load "shared/util.scm")
(load "shared/sicp-query.scm")
(initialize-data-base microshaft-data-base)

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-query.scm")
(load "shared/util.scm")
(load "shared/sicp-query.scm")
(initialize-data-base microshaft-data-base)

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-query.scm")
(load "shared/util.scm")
(load "shared/sicp-query.scm")
(initialize-data-base microshaft-data-base)

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-ambeval.scm")
(load "shared/util.scm")
(load "shared/sicp-ambeval.scm")
(define the-global-environment (setup-environment))
(define result '())

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-regsim.scm")
(load "shared/util.scm")
(load "shared/sicp-regsim.scm")
(display "\nex-5.1 draw-factorial\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-regsim.scm")
(load "shared/util.scm")
(load "shared/sicp-regsim.scm")
(display "\nex-5.7 - test-machines\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-regsim.scm")
(load "shared/util.scm")
(load "shared/sicp-regsim.scm")
(display "\nex-5.14 - factorial-stack-evaluation\n")

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-regsim.scm")
(load "shared/util.scm")
(load "shared/sicp-regsim.scm")
(display "\nex-5.20 - box-and-pointer\n")

View File

@ -1,7 +1,7 @@
(load "util.scm")
(load "misc/sicp-regsim.scm")
(load "misc/sicp-eceval.scm")
(load "misc/sicp-eceval-lazy.scm")
(load "shared/util.scm")
(load "shared/sicp-regsim.scm")
(load "shared/sicp-eceval.scm")
(load "shared/sicp-eceval-lazy.scm")
(define the-global-environment (setup-environment))
(set-register-contents! eceval 'exp '(if false 1 2))

View File

@ -1,4 +1,4 @@
(load "misc/sicp-compiler.scm")
(load "shared/sicp-compiler.scm")
(define (compile-to-file code target linkage file-name)
(set! label-counter 0)

View File

@ -1,5 +1,5 @@
(load "util.scm")
(load "misc/sicp-compiler-lexical-addressing.scm")
(load "shared/util.scm")
(load "shared/sicp-compiler-lexical-addressing.scm")
(define (compile-to-file code target linkage file-name)
(set! label-counter 0)

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -8,6 +8,10 @@
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; felixm: This amb implementation does not manage the state of defines. That
; means procedures that use define and set! will not work. To make all amb
; procedures work I had to use the amb evaluator from the book.
;;; abbreviation for call-with-current-continuation
(define call/cc call-with-current-continuation)
@ -92,7 +96,7 @@
(amb i (loop (1+ i))))))
;;;;;;;;;;;; misc
;;;;;;;;;;;; other
(define (gen-prime n)
(let ((i (number-between 2 n)))
(assert (prime? i))

View File

@ -1,5 +1,5 @@
(define (draw-to-py painter name)
(define py-name (string-append "misc/" name ".py"))
(define py-name (string-append "shared/" name ".py"))
(define img-name (string-append name ".png"))
(define head (string-append
"from PIL import Image, ImageDraw\n"

View File

@ -12,8 +12,8 @@
;;;;Then you can compile Scheme programs as shown in section 5.5.5
;;**implementation-dependent loading of syntax procedures
(load "misc/sicp-syntax.scm") ;section 4.1.2 syntax procedures
(load "misc/sicp-eceval-support.scm") ;; for let support
(load "shared/sicp-syntax.scm") ;section 4.1.2 syntax procedures
(load "shared/sicp-eceval-support.scm") ;; for let support
;;;SECTION 5.5.1

View File

@ -12,7 +12,7 @@
;;;;Then you can compile Scheme programs as shown in section 5.5.5
;;**implementation-dependent loading of syntax procedures
(load "misc/sicp-syntax.scm") ;section 4.1.2 syntax procedures
(load "shared/sicp-syntax.scm") ;section 4.1.2 syntax procedures
;;;SECTION 5.5.1

View File

@ -1,7 +1,7 @@
; Uncomment the import if you want to use the lazy-evaluator standalone. We
; only use it in ex-5_23-30.scm right now and in that context everything is
; already imported for the regular evaluator.
;(load "misc/sicp-eceval-support.scm")
;(load "shared/sicp-eceval-support.scm")
; Below is the original version of the evaluator-machine from the book modified
; for lazy-evaluation.

View File

@ -4,8 +4,8 @@
;;;;FIRST A LOT FROM 4.1.2-4.1.4
;(load "sicp-syntax.scm"); ;section 4.1.2 syntax procedures
(load "misc/sicp-eceval-syntax.scm") ;section 4.1.2 syntax procedures
(load "misc/sicp-leval.scm") ; for lazy evaluation in eceval
(load "shared/sicp-eceval-syntax.scm") ;section 4.1.2 syntax procedures
(load "shared/sicp-leval.scm") ; for lazy evaluation in eceval
;;;SECTION 4.1.3
;;; operations used by compiled code and eceval except as noted

View File

@ -1,7 +1,7 @@
; Copied and adapted from:
; https://mitpress.mit.edu/sites/default/files/sicp/code/index.html
(load "misc/sicp-eceval-support.scm")
(load "shared/sicp-eceval-support.scm")
; To run:
; - Setup global environment