From 70be49b957603065eafd2fa8c526bb6ff5f49b57 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 30 Apr 2022 00:23:38 +0200 Subject: [PATCH] Start Common examples. --- scribblings/networks.scrbl | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) 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)) ]}