diff --git a/bn-tests.rkt b/bn-tests.rkt index 0238c49..8dec81e 100644 --- a/bn-tests.rkt +++ b/bn-tests.rkt @@ -30,4 +30,9 @@ [new-s (update bn s '(x2 x1))]) (check-equal? (hash-ref new-s 'x1) #f) (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 "Constructing networks from forms" + (let ([s (make-state '((x . #t) (y . #f)))] + [f (update-func-form->update-func '(and x y))]) + (check-equal? (f s) #f)))))) diff --git a/bn.rkt b/bn.rkt index d318804..9d3fe20 100644 --- a/bn.rkt +++ b/bn.rkt @@ -7,8 +7,10 @@ ;;; are updated according to their corresponding update functions. ;;; The variables to be updated at each step are given by the mode. +(require "utils.rkt") + (provide Variable State UpdateFunc Network - update make-state make-bn) + update make-state make-bn update-func-form->update-func) ;;; ================= @@ -65,3 +67,8 @@ ;;; forms of their update functions. (define-type NetworkForm (HashTable Variable UpdateFuncForm)) +;;; Build an update function from an update function form. +#;(: update-func-form->update-func (-> UpdateFuncForm UpdateFunc)) +(define (update-func-form->update-func form) + (lambda ([s : State]) + (cast (eval-with1 (cast s (HashTable Variable Any)) form) Boolean)))