learning-sicp

My embarrassing half assed SICP run.
Log | Files | Refs

commit 46989fdf7512d7d702ac20fc3b5643668052f2ab
parent 628ab61366b9134104882076e95c6b9f3200a431
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Sun, 16 Apr 2023 12:22:36 +0300

Add exercise 3.15 solution.

Diffstat:
Asicp/tests/3_15.scm | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+), 0 deletions(-)

diff --git a/sicp/tests/3_15.scm b/sicp/tests/3_15.scm @@ -0,0 +1,78 @@ +(define-library (sicp tests 3_15) + (import (scheme base)) + (import (srfi :64)) + + (begin + (test-begin "3.15") + + (define (set-to-wow! x) + (set-car! (car x) 'wow) + x) + + (define x (list 'a 'b)) + (define z1 (cons x x)) + (define z2 (cons (list 'a 'b) + (list 'a 'b))) + ;; +---+---+ + ;; z1: --> | * | * | + ;; +-|-+-|-+ + ;; V V + ;; +---+---+ +---+---+ + ;; x: --> | * | *-+---->| * | / | + ;; +-|-+---+ +-|-+---+ + ;; V V + ;; +---+ +---+ + ;; | a | | b | + ;; +---+ +---+ + ;; + ;; +---+---+ +---+---+ +---+---+ + ;; z2: --> | * | * +---->| * | *-+--->| * | / | + ;; +-|-+---+ +-|-+---+ +-|-+---+ + ;; | V V + ;; | +---+ +---+ + ;; | | a | | b | + ;; | +---+ +---+ + ;; | ^ ^ + ;; | | | + ;; | +-|-+---+ +-|-+---+ + ;; +---------->| * | *-+--->| * | / | + ;; +---+---+ +---+---+ + (test-equal '(a b) x) + (test-equal '((a b) a b) z1) + (test-equal '((a b) a b) z2) + + (set-to-wow! z1) + (set-to-wow! z2) + ;; +---+---+ + ;; z1: --> | * | * | + ;; +-|-+-|-+ + ;; V V + ;; +---+---+ +---+---+ + ;; x: --> | * | *-+---->| * | / | + ;; +-|-+---+ +-|-+---+ + ;; V V + ;; +-----+ +---+ + ;; | wow | | b | + ;; +-----+ +---+ + ;; + ;; +---+---+ +---+---+ +---+---+ + ;; z2: --> | * | * +---->| * | *-+--->| * | / | + ;; +-|-+---+ +-|-+---+ +-|-+---+ + ;; | V V + ;; | +---+ +---+ + ;; | | a | | b | + ;; | +---+ +---+ + ;; | ^ + ;; | +-----+ | + ;; | | wow | | + ;; | +-----+ | + ;; | ^ | + ;; | | | + ;; | +-|-+---+ +-|-+---+ + ;; +---------->| * | *-+--->| * | / | + ;; +---+---+ +---+---+ + (test-equal '(wow b) x) + (test-equal '((wow b) wow b) z1) + (test-equal '((wow b) a b) z2) + + (test-end "3.15")))