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
1 changed files with 5 additions and 8 deletions

View File

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