Some more progress. I really should read more of this book.

This commit is contained in:
2025-06-22 13:57:16 +03:00
committed by Emin Arslan
parent 9a365b2ed4
commit 7795821459
4 changed files with 57 additions and 6 deletions

View File

@ -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)

52
sec-3-3-4.scm Normal file
View File

@ -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))

View File

@ -128,7 +128,3 @@ x ; => '(a b c d)
(loop x)
(vector-length (hashtable-values table)))

BIN
sec-3-3.so Normal file

Binary file not shown.