commit dfabd902350bfe9a3af6fb7d0dbcb2c5378daa0d parent c82ea4c476631ffe8bd482dc14ad43c2e161f967 Author: Yuval Langer <yuval.langer@gmail.com> Date: Tue, 14 Nov 2023 03:13:55 +0200 Do more renamings and move chapter-2-exercise-4 to the right place. Diffstat:
24 files changed, 119 insertions(+), 119 deletions(-)
diff --git a/sicp/solutions/chapter-1/exercise-34.scm b/sicp/solutions/chapter-1/exercise-34.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 1_34) +(define-library (sicp solutions chapter-1 exercise-34) (import (scheme base)) (begin diff --git a/sicp/solutions/chapter-1/exercise-42.scm b/sicp/solutions/chapter-1/exercise-42.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 1_42) +(define-library (sicp solutions chapter-1 exercise-42) (import (scheme base)) (begin diff --git a/sicp/solutions/chapter-2/exercise-2_4-complex-numbers.scm b/sicp/solutions/chapter-2/exercise-2_4-complex-numbers.scm @@ -1,80 +0,0 @@ -(define-library (2_4-complex-numbers) - (import (scheme base)) - - (begin - (define (type-tag datum) - (if (and (pair? datum) - (symbol? (car datum))) - (car datum) - (error "Bad tagged datum: TYPE-TAG " datum))) - - (define (contents datum) - (if (and (pair? datum) - (symbol? (car datum))) - (cdr datum) - (error "Bad tagged datum: CONTENTS " datum))) - - (define (rectangular? z) - (eq? (type-tag z) 'rectangular)) - - (define (polar? z) - (eq? (type-tag z) 'polar)) - - ;; Ben representation - - (define (real-part-rectangular z) (car z)) - (define (imag-part-rectangular z) (cdr z)) - - (define (magnitude-rectangular z) - (sqrt (+ (square (real-part-rectangular z)) - (square (imag-part-rectangular z))))) - - (define (angle-rectangular z) - (atan (imag-part-rectangular z) - (real-part-rectangular z))) - - (define (make-from-real-imag-rectangular x y) - (attach-tag 'rectangular (cons x y))) - - (define (make-from-mag-ang-rectangular r a) - (attach-tag - 'rectangular - (cons (* r (cos a)) - (* r (sin a))))) - - ;; Alyssa representation - - (define (real-part-polar z) - (* (magnitude-poler z) - (cos (angle-polar z)))) - - (define (imag-part-polar z) - (* (magnitude-poler z) - (sin (angle-polar z)))) - - (define (magnitude-part-polar z) - (car z)) - - (define (angle-part-polar z) - (cdr z)) - - (define (make-from-real-imag real imag) - (list 'complex-real-imag real imag)) - - (define (make-from-mag-ang mag ang) - (list 'comlex-mag-ang mag ang)) - - (define (add-complex z1 z2) - (make-from-real-imag - (+ (real-part z1) (real-part z2)) - (+ (imag-part z1) (imag-part z2)))) - - (define (mul-complex z1 z2) - (make-from-real-imag - (* (magnitude z1) (magnitude z2)) - (+ (angle z1) (angle z2)))) - - (define (sub-complex z1 z2) - (make-from-real-imag - (/ (magnitude z1) (magnitude z2)) - (- (angle z1) (angle z2)))))) diff --git a/sicp/solutions/chapter-2/exercise-4.scm b/sicp/solutions/chapter-2/exercise-4.scm @@ -1,23 +1,80 @@ -;; Exercise 2.4 +(define-library (sicp solutions chapter-2 exercise-4) + (import (scheme base)) -(test-begin "2.4") + (begin + (define (type-tag datum) + (if (and (pair? datum) + (symbol? (car datum))) + (car datum) + (error "Bad tagged datum: TYPE-TAG " datum))) -(let ((cons (lambda (x y) (lambda (m) (m x y)))) - (car (lambda (z) (z (lambda (p q) p)))) - (cdr (lambda (z) (z (lambda (p q) q))))) + (define (contents datum) + (if (and (pair? datum) + (symbol? (car datum))) + (cdr datum) + (error "Bad tagged datum: CONTENTS " datum))) + (define (rectangular? z) + (eq? (type-tag z) 'rectangular)) - (for-each - (lambda (matsui) (test-equal 'x matsui)) - (list (car (cons 'x 'y)) - (car (lambda (m) (m 'x 'y))) - ((lambda (m) (m 'x 'y)) (lambda (p q) p)) - ((lambda (p q) p) 'x 'y))) - (for-each - (lambda (matsui) (test-equal 'y matsui)) - (list (cdr (cons 'x 'y)) - (cdr (lambda (m) (m 'x 'y))) - ((lambda (m) (m 'x 'y)) (lambda (p q) q)) - ((lambda (p q) q) 'x 'y)))) + (define (polar? z) + (eq? (type-tag z) 'polar)) -(test-end "2.4") + ;; Ben representation + + (define (real-part-rectangular z) (car z)) + (define (imag-part-rectangular z) (cdr z)) + + (define (magnitude-rectangular z) + (sqrt (+ (square (real-part-rectangular z)) + (square (imag-part-rectangular z))))) + + (define (angle-rectangular z) + (atan (imag-part-rectangular z) + (real-part-rectangular z))) + + (define (make-from-real-imag-rectangular x y) + (attach-tag 'rectangular (cons x y))) + + (define (make-from-mag-ang-rectangular r a) + (attach-tag + 'rectangular + (cons (* r (cos a)) + (* r (sin a))))) + + ;; Alyssa representation + + (define (real-part-polar z) + (* (magnitude-poler z) + (cos (angle-polar z)))) + + (define (imag-part-polar z) + (* (magnitude-poler z) + (sin (angle-polar z)))) + + (define (magnitude-part-polar z) + (car z)) + + (define (angle-part-polar z) + (cdr z)) + + (define (make-from-real-imag real imag) + (list 'complex-real-imag real imag)) + + (define (make-from-mag-ang mag ang) + (list 'comlex-mag-ang mag ang)) + + (define (add-complex z1 z2) + (make-from-real-imag + (+ (real-part z1) (real-part z2)) + (+ (imag-part z1) (imag-part z2)))) + + (define (mul-complex z1 z2) + (make-from-real-imag + (* (magnitude z1) (magnitude z2)) + (+ (angle z1) (angle z2)))) + + (define (sub-complex z1 z2) + (make-from-real-imag + (/ (magnitude z1) (magnitude z2)) + (- (angle z1) (angle z2)))))) diff --git a/sicp/solutions/chapter-3/exercise-1.scm b/sicp/solutions/chapter-3/exercise-1.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_1) +(define-library (sicp solutions chapter-3 exercise-1) (import (scheme base)) (export make-accumulator) diff --git a/sicp/solutions/chapter-3/exercise-14.scm b/sicp/solutions/chapter-3/exercise-14.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_14) +(define-library (sicp solutions chapter-3 exercise-14) (import (scheme base)) (export mystery) diff --git a/sicp/solutions/chapter-3/exercise-17.scm b/sicp/solutions/chapter-3/exercise-17.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_17) +(define-library (sicp solutions chapter-3 exercise-17) (import (scheme base)) (export count-pairs) diff --git a/sicp/solutions/chapter-3/exercise-18.scm b/sicp/solutions/chapter-3/exercise-18.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_18) +(define-library (sicp solutions chapter-3 exercise-18) (import (scheme base)) (export cyclic?) diff --git a/sicp/solutions/chapter-3/exercise-19.scm b/sicp/solutions/chapter-3/exercise-19.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_19) +(define-library (sicp solutions chapter-3 exercise-19) (import (scheme base)) (export cyclic?) diff --git a/sicp/solutions/chapter-3/exercise-2.scm b/sicp/solutions/chapter-3/exercise-2.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_2) +(define-library (sicp solutions chapter-3 exercise-2) (import (scheme base)) (export make-monitored) diff --git a/sicp/solutions/chapter-3/exercise-21.scm b/sicp/solutions/chapter-3/exercise-21.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_21) +(define-library (sicp solutions chapter-3 exercise-21) (import (scheme base)) (import (scheme write)) (export diff --git a/sicp/solutions/chapter-3/exercise-22.scm b/sicp/solutions/chapter-3/exercise-22.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_22) +(define-library (sicp solutions chapter-3 exercise-22) (import (scheme base)) (import (scheme write)) (export diff --git a/sicp/solutions/chapter-3/exercise-25.scm b/sicp/solutions/chapter-3/exercise-25.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_25) +(define-library (sicp solutions chapter-3 exercise-25) (import (scheme base)) (import (scheme write)) diff --git a/sicp/solutions/chapter-3/exercise-3.scm b/sicp/solutions/chapter-3/exercise-3.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_3) +(define-library (sicp solutions chapter-3 exercise-3) (import (scheme base)) (export make-account) diff --git a/sicp/solutions/chapter-3/exercise-4.scm b/sicp/solutions/chapter-3/exercise-4.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_4) +(define-library (sicp solutions chapter-3 exercise-4) (import (scheme base)) (export make-account) diff --git a/sicp/solutions/chapter-3/exercise-5.scm b/sicp/solutions/chapter-3/exercise-5.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_5) +(define-library (sicp solutions chapter-3 exercise-5) (import (scheme base)) (import (srfi :64 diff --git a/sicp/solutions/chapter-3/exercise-6.scm b/sicp/solutions/chapter-3/exercise-6.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_6) +(define-library (sicp solutions chapter-3 exercise-6) (import (scheme base)) (import (only (guile) *random-state* diff --git a/sicp/solutions/chapter-3/exercise-7.scm b/sicp/solutions/chapter-3/exercise-7.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_7) +(define-library (sicp solutions chapter-3 exercise-7) (import (scheme base)) (export make-joint diff --git a/sicp/solutions/chapter-3/exercise-8.scm b/sicp/solutions/chapter-3/exercise-8.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_8) +(define-library (sicp solutions chapter-3 exercise-8) (import (scheme base)) (export make-f diff --git a/sicp/solutions/chapter-3/exercise-9.scm b/sicp/solutions/chapter-3/exercise-9.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions 3_9) +(define-library (sicp solutions chapter-3 exercise-9) (import (scheme base)) (begin diff --git a/sicp/tests/chapter-2/exercise-4.scm b/sicp/tests/chapter-2/exercise-4.scm @@ -0,0 +1,23 @@ +;; Exercise 2.4 + +(test-begin "chapter-2-exercise-4") + +(let ((cons (lambda (x y) (lambda (m) (m x y)))) + (car (lambda (z) (z (lambda (p q) p)))) + (cdr (lambda (z) (z (lambda (p q) q))))) + + + (for-each + (lambda (matsui) (test-equal 'x matsui)) + (list (car (cons 'x 'y)) + (car (lambda (m) (m 'x 'y))) + ((lambda (m) (m 'x 'y)) (lambda (p q) p)) + ((lambda (p q) p) 'x 'y))) + (for-each + (lambda (matsui) (test-equal 'y matsui)) + (list (cdr (cons 'x 'y)) + (cdr (lambda (m) (m 'x 'y))) + ((lambda (m) (m 'x 'y)) (lambda (p q) q)) + ((lambda (p q) q) 'x 'y)))) + +(test-end "chapter-2-exercise-4") diff --git a/sicp/tests/chapter-3/exercise-1.scm b/sicp/tests/chapter-3/exercise-1.scm @@ -1,7 +1,7 @@ (define-library (sicp tests chapter-3 exercise-1) (import (scheme base) (srfi :64) - (sicp solutions 3_1)) + (sicp solutions chapter-3 exercise-1)) (begin (define A (make-accumulator 5)) diff --git a/sicp/tests/chapter-3/exercise-2.scm b/sicp/tests/chapter-3/exercise-2.scm @@ -1,7 +1,7 @@ (define-library (sicp tests chapter-3 exercise-2) (import (scheme base) (srfi :64) - (sicp solutions 3_2)) + (sicp solutions chapter-3 exercise-2)) (begin (define s (make-monitored sqrt)) diff --git a/sicp/tests/chapter-3/exercise-3.scm b/sicp/tests/chapter-3/exercise-3.scm @@ -1,7 +1,7 @@ (define-library (sicp tests chapter-3 exercise-3) (import (scheme base) (srfi :64) - (sicp solutions 3_3)) + (sicp solutions chapter-3 exercise-3)) (begin (define acc