From 7795821459302768698a08bc02cf9d81a52a1ee3 Mon Sep 17 00:00:00 2001 From: haxala1r Date: Sun, 22 Jun 2025 13:57:16 +0300 Subject: [PATCH] Some more progress. I really should read more of this book. --- ex-1-11.rkt | 7 +++++-- sec-3-3-4.scm | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ sec-3-3.scm | 4 ---- sec-3-3.so | Bin 0 -> 6662 bytes 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 sec-3-3-4.scm create mode 100644 sec-3-3.so 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 0000000000000000000000000000000000000000..e34990954e86c9245ea60d1a529406a4ad306a9d GIT binary patch literal 6662 zcmeI1eQXo=8ONXBz58OvcV{4u8E?TDh;W?55GS-1F)yp#5tek)=tjqMw$HJN-?+1b zgJ2^Gw0J39sU}u!86bozR#j8i{nKuUc2XJD_7Cc`Nt5;mTZIHg(+t_7RU68lv$2yR z*no8_lZfKWC9!kA^YeVapWpKh06;XM?Y(&L0JvAJUNO3|EjH@=`+A81r<0PQS*9J0 zx)#l*bIFwEO=jX*XFO9V4i6QEjqYN5F%s?SPWTh)E^kM_Wg#$>l~Vv*?cf>%7XbAH zOsxT)Vpy3_bUYQK8j|T;R?mBNZFj4clPSt(-~!T`HyhcdMe{C&VHHAIlbL9$5Ytvd znNuiNi`4@z0Tddn9N@Xtvw~R@vo^X9TiRmZ>YUyzDZm9A-i5DPITz*Z=Bg{VM6fYyxa;rS6{hoqi92q-hIui zuBoXs-aoEahNE&L#Tr^Mr#nFIbi)7>*ELN7WupY0spK%8JuN{{&m|2Bei4~-gEUNm z%rF27gP&GU=xrdNg^mocp>vHeZ7FqzCw4v)?)jbJ4vk+E!lj+hgi4OkPnSWN8L)*e zoNvRT24^$~y)}a$&9HRlVh>Dl*M7;sCI_$Pa#|*~%+{LE=33V`!f9y4x2_jPQ!AH3 zuS;-tZy;r-b15xz%`)%cjBG)VYR*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