networks: Rewrite update for immutable hashes.

This commit is contained in:
Sergiu Ivanov 2020-02-23 09:19:45 +01:00
parent 1492c33e1a
commit 4a6888ddde

View file

@ -63,14 +63,11 @@
;;; Given a state s updates all the variables from xs. This ;;; Given a state s updates all the variables from xs. This
;;; corresponds to a parallel mode. ;;; corresponds to a parallel mode.
(define (update n ; the network (define (update network s xs)
s ; the state to operate on (for/fold ([new-s s])
xs) ; the variables to update ([x xs])
(let ([new-s (hash-copy s)]) (let ([f (hash-ref network x)])
(for ([x xs]) (hash-set new-s x (f s)))))
(let ([f (hash-ref n x)])
(hash-set! new-s x (f s))))
new-s))
;;; A version of make-immutable-hash restricted to creating network ;;; A version of make-immutable-hash restricted to creating network
;;; states (see contract). ;;; states (see contract).