From 4a6888dddec8cfb7639c5ebbe2b63b67c98820a6 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 23 Feb 2020 09:19:45 +0100 Subject: [PATCH] networks: Rewrite update for immutable hashes. --- networks.rkt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/networks.rkt b/networks.rkt index 0c12d86..cfb21e3 100644 --- a/networks.rkt +++ b/networks.rkt @@ -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).