From f0a7c270e9b0af6587c16c062d342a045414139e Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 18 Feb 2020 12:16:03 +0100 Subject: [PATCH] bn: Add make-bn-forms. --- bn-tests.rkt | 8 +++++--- bn.rkt | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bn-tests.rkt b/bn-tests.rkt index dc65f01..a4c69d8 100644 --- a/bn-tests.rkt +++ b/bn-tests.rkt @@ -36,7 +36,9 @@ (let ([s (make-state '((x . #t) (y . #f)))] [f (update-func-form->update-func '(and x y))]) (check-equal? (f s) #f)) - (let ([bn (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))] + (let ([bn1 (bn-form->bn (make-hash '((a . (and a b)) (b . (not b)))))] + [bn2 (make-bn-forms '((a . (and a b)) + (b . (not b))))] [s (make-state '((a . #t) (b . #t)))]) - (check-equal? ((hash-ref bn 'a) s) - #t)))))) + (check-equal? ((hash-ref bn1 'a) s) #t) + (check-equal? ((hash-ref bn2 'a) s) #t)))))) diff --git a/bn.rkt b/bn.rkt index 035ac4e..2164c9f 100644 --- a/bn.rkt +++ b/bn.rkt @@ -11,7 +11,7 @@ (provide Variable State UpdateFunc Network update make-state make-bn-funcs update-func-form->update-func - bn-form->bn) + bn-form->bn make-bn-forms) ;;; ================= @@ -80,3 +80,14 @@ (make-hash (hash-map bnf (lambda ([x : Variable] [form : UpdateFuncForm]) (cons x (update-func-form->update-func form)))))) + +;;; Build a network from a list of pairs of forms of update functions. +(: make-bn-forms (-> (Listof (Pairof Variable UpdateFuncForm)) Network)) +(define (make-bn-forms forms) + (bn-form->bn (make-hash forms))) + +(let ([bn (make-bn-forms '((a . (and a b)) + (b . (not b))))] + [s (make-state '((a . #t) + (b . #t)))]) + ((hash-ref bn 'a) s))