diff --git a/ex-1-11.rkt b/ex-1-11.rkt index 97f7d88..8d6b95f 100644 --- a/ex-1-11.rkt +++ b/ex-1-11.rkt @@ -14,9 +14,9 @@ (define-syntax-rule (meas form) - (let ([my-time (current-inexact-milliseconds)]) + (let ([my-time (real-time)]) (let ([res form]) - (- (current-inexact-milliseconds) my-time)))) + (- (real-time) my-time)))) (define (recursive n) @@ -32,6 +32,9 @@ (define (iter-start n) (iter 0 1 2 (- n 2))) +;; note, as the book says, +;; this generates an *iterative process*, despite being +;; fully recursive (define (ex-1-11 n) (let loop ((i n)) (if (< i 2) diff --git a/sec-3-3-4.scm b/sec-3-3-4.scm new file mode 100644 index 0000000..0a88520 --- /dev/null +++ b/sec-3-3-4.scm @@ -0,0 +1,52 @@ + +;; The digital circuit program is very interesting, +;; not just because it is a good demonstration of scheme, +;; but also because I really think this is a practical +;; program. + +;; anyway, here are the exercises + +;; so, the book does not provide an implementation for make-wire, +;; get-signal, set-signal!, add-action! and after-delay +;; so if we want this code to run, we need to implement them. + +;; I chose to use a closure for this, because this is something +;; I really learned with SICP so may as well. We could also use +;; a box (in r6rs I believe, or at least chez) +;; and in all fairness I believe that is more efficient, however this was funny + +;; EDIT: later on in the chapter the book actually provides a similar implementation +;; so I guess I'm prescient now +(define (make-wire) + (let ((val #f) (actions '())) + (lambda (x param) + (cond + ((eq? x 'get) val) + ((eq? x 'set!) + (if (not (boolean=? val param)) + (begin (set! val param) + (map (lambda (x) (x)) + actions)))) + ((eq? x 'add-action!) + (set! actions (cons param actions)) + (param)))))) + +(define (get-signal w) + (w 'get 'USELESS)) +(define (set-signal! w val) + (w 'set! val)) +(define (add-action! w action) + (w 'add-action! action)) + + +(define a (make-wire)) +(define b (make-wire)) +(define c (make-wire)) +(define d (make-wire)) +(define e (make-wire)) +(define s (make-wire)) + + + + + diff --git a/sec-3-3.scm b/sec-3-3.scm index 30b11a0..ba5fdce 100644 --- a/sec-3-3.scm +++ b/sec-3-3.scm @@ -128,7 +128,3 @@ x ; => '(a b c d) (loop x) (vector-length (hashtable-values table))) - - - - diff --git a/sec-3-3.so b/sec-3-3.so new file mode 100644 index 0000000..e349909 Binary files /dev/null and b/sec-3-3.so differ