diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 110fc0a..51d2bab 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -62,6 +62,24 @@ their domains. } +@section{Common examples} + +The examples in this document often use the same definitions, which are +therefore grouped here to avoid duplicating them. + +These are two functions calculating an @italic{AND} and an @italic{OR} between +the variables @racket[a] and @racket[b]: + +@ex[ +(: or-func (UpdateFunction Boolean)) +(define (or-func s) + (or (hash-ref s 'a) (hash-ref s 'b))) + +(: and-func (UpdateFunction Boolean)) +(define (and-func s) + (and (hash-ref s 'a) (hash-ref s 'b))) +] + @section{Networks} @defstruct*[network ([functions (VariableMapping (UpdateFunction a))] @@ -79,14 +97,6 @@ Instances of @racket[network] have the type @racket[Network]. The type of the instances of @racket[Network]. @ex[ -(: or-func (UpdateFunction Boolean)) -(define (or-func s) - (or (hash-ref s 'a) (hash-ref s 'b))) - -(: and-func (UpdateFunction Boolean)) -(define (and-func s) - (and (hash-ref s 'a) (hash-ref s 'b))) - (network (hash 'a or-func 'b and-func) (hash 'a '(#f #t) @@ -119,14 +129,6 @@ Builds a Boolean network from a given hash table assigning functions to variables by attributing Boolean domains to every variable. @ex[ -(: or-func (UpdateFunction Boolean)) -(define (or-func s) - (or (hash-ref s 'a) (hash-ref s 'b))) - -(: and-func (UpdateFunction Boolean)) -(define (and-func s) - (and (hash-ref s 'a) (hash-ref s 'b))) - (make-boolean-network (hash 'a or-func 'b and-func)) ]}