learning-sicp

My embarrassing half assed SICP run.
git clone https://kaka.farm/~git/learning-sicp
Log | Files | Refs

commit 0c8b4d36641704f91d13eb8c3abe1442e3bba6e0
parent c6fdb9e2312602f026cadfa5abbd9f3bb824089b
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Fri,  2 Aug 2024 11:29:48 +0300

Fix solution numbers in library names and test name. - change from 13 to 14.  Also add tests.

Diffstat:
Msicp/solutions/chapter-4/exercise-14.scm | 2+-
Msicp/tests/chapter-4/exercise-14.scm | 47+++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/sicp/solutions/chapter-4/exercise-14.scm b/sicp/solutions/chapter-4/exercise-14.scm @@ -1,4 +1,4 @@ -(define-library (sicp solutions chapter-4 exercise-13) +(define-library (sicp solutions chapter-4 exercise-14) (export eval main diff --git a/sicp/tests/chapter-4/exercise-14.scm b/sicp/tests/chapter-4/exercise-14.scm @@ -1,9 +1,9 @@ -(define-library (sicp tests chapter-4 exercise-13) +(define-library (sicp tests chapter-4 exercise-14) (import (scheme base) (srfi :64) - (sicp solutions chapter-4 exercise-13) + (sicp solutions chapter-4 exercise-14) (sicp utils)) @@ -12,7 +12,46 @@ ;; TODO: Not sure if this is the real solution. - (test-begin "chapter-4-exercise-13") + (test-begin "chapter-4-exercise-14") + + (test-equal 1 + (eval '(begin + (define (map f l) + (cond + ((null? l) + '()) + (else + (cons (f (car l)) + (map f (cdr l)))))) + (car (map (lambda (x) (+ x 1)) + '(0 1 2)))) + (setup-environment))) + + (test-equal 0 + (eval '(begin + (define (map f l) + (cond + ((null? l) + '()) + (else + (cons (f (car l)) + (map f (cdr l)))))) + (car (map (lambda (x) (- x 1)) + '(0 1 2)))) + (setup-environment))) + + (test-equal '(2 3) + (eval '(begin + (define (map f l) + (cond + ((null? l) + '()) + (else + (cons (f (car l)) + (map f (cdr l)))))) + (cdr (map (lambda (x) (+ x 1)) + '(0 1 2)))) + (setup-environment))) (test-equal 1 (eval '1 @@ -59,5 +98,5 @@ (+ a b))) ;; a = a + b = 1 + 4 = 5 (setup-environment))) - (test-end "chapter-4-exercise-13") + (test-end "chapter-4-exercise-14") ))