bn: Add and use new-state.
This commit is contained in:
parent
faf8f70b2e
commit
1e931102d6
2 changed files with 7 additions and 3 deletions
|
@ -19,14 +19,14 @@
|
||||||
[bn (hash 'x1 f1 'x2 f2)])
|
[bn (hash 'x1 f1 'x2 f2)])
|
||||||
|
|
||||||
(test-case "One-step syncronous update"
|
(test-case "One-step syncronous update"
|
||||||
(let* ([s (hash 'x1 #t 'x2 #f)]
|
(let* ([s (new-state '((x1 . #t) (x2 . #f)))]
|
||||||
[new-s (update bn s '(x2 x1))])
|
[new-s (update bn s '(x2 x1))])
|
||||||
(check-equal? (hash-ref new-s 'x1) #t)
|
(check-equal? (hash-ref new-s 'x1) #t)
|
||||||
(check-equal? (hash-ref new-s 'x2) #t)
|
(check-equal? (hash-ref new-s 'x2) #t)
|
||||||
(check-equal? (length (hash-keys new-s)) 2)))
|
(check-equal? (length (hash-keys new-s)) 2)))
|
||||||
|
|
||||||
(test-case "One-step asynchronous update"
|
(test-case "One-step asynchronous update"
|
||||||
(let* ([s (hash 'x1 #f 'x2 #f)]
|
(let* ([s (new-state '((x1 . #f) (x2 . #f)))]
|
||||||
[new-s (update bn s '(x2 x1))])
|
[new-s (update bn s '(x2 x1))])
|
||||||
(check-equal? (hash-ref new-s 'x1) #f)
|
(check-equal? (hash-ref new-s 'x1) #f)
|
||||||
(check-equal? (hash-ref new-s 'x2) #t)
|
(check-equal? (hash-ref new-s 'x2) #t)
|
||||||
|
|
6
bn.rkt
6
bn.rkt
|
@ -8,7 +8,7 @@
|
||||||
;;; The variables to be updated at each step are given by the mode.
|
;;; The variables to be updated at each step are given by the mode.
|
||||||
|
|
||||||
(provide Variable State UpdateFunc Network
|
(provide Variable State UpdateFunc Network
|
||||||
update)
|
update new-state)
|
||||||
|
|
||||||
(define-type Variable Symbol)
|
(define-type Variable Symbol)
|
||||||
|
|
||||||
|
@ -34,3 +34,7 @@
|
||||||
(let ([f (hash-ref bn x)])
|
(let ([f (hash-ref bn x)])
|
||||||
(hash-set! new-s x (f s))))
|
(hash-set! new-s x (f s))))
|
||||||
new-s))
|
new-s))
|
||||||
|
|
||||||
|
;;; A version of make-hash restricted to creating Boolean states.
|
||||||
|
(define (new-state [mappings : (Listof (Pairof Variable Boolean))])
|
||||||
|
(make-hash mappings))
|
||||||
|
|
Loading…
Reference in a new issue