bn: Add update-func-form->update-func.

This commit is contained in:
Sergiu Ivanov 2020-02-18 11:41:16 +01:00
parent a061e2d7bc
commit 7a4dd09f40
2 changed files with 14 additions and 2 deletions

View file

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

9
bn.rkt
View file

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