Start Common examples.

This commit is contained in:
Sergiu Ivanov 2022-04-30 00:23:38 +02:00
parent 5da523d297
commit 70be49b957
1 changed files with 18 additions and 16 deletions

View File

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