commit fb2fbcfe232da967776c979fba70148aa9f6302c parent 51c54867ee7da55a16dba28cc7543b2306785fbf Author: Yuval Langer <yuval.langer@gmail.com> Date: Sun, 2 Apr 2023 15:56:46 +0300 Add exercise 3.1 solution. Diffstat:
A | sicp/solutions/3_1.scm | | | 9 | +++++++++ |
A | sicp/tests/3_1.scm | | | 20 | ++++++++++++++++++++ |
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/sicp/solutions/3_1.scm b/sicp/solutions/3_1.scm @@ -0,0 +1,9 @@ +(define-library (sicp solutions 3_1) + (import (scheme base)) + (export make-accumulator) + + (begin + (define (make-accumulator n) + (lambda (x) + (set! n (+ n x)) + n)))) diff --git a/sicp/tests/3_1.scm b/sicp/tests/3_1.scm @@ -0,0 +1,20 @@ +(import (srfi :64)) +(import (sicp solutions 3_1)) + +(define A (make-accumulator 5)) +(define B (make-accumulator 0)) + +(test-begin "3.1") +(test-equal + 15 + (A 10)) +(test-equal + 10 + (B 10)) +(test-equal + 25 + (A 10)) +(test-equal + 20 + (B 10)) +(test-end "3.1")