From 54569ea2e5586e4b60341c3c9cbfd4a590c85ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 6 Apr 2023 19:21:50 +0200 Subject: [PATCH] Functional dict-update. --- src/dictionary.scm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dictionary.scm b/src/dictionary.scm index 966ba61..164776a 100644 --- a/src/dictionary.scm +++ b/src/dictionary.scm @@ -37,6 +37,7 @@ dict-map dict-filter dict-reduce + dict-update dictionary-tests! ) @@ -145,6 +146,11 @@ (loop (cdr d) (proc acc (caar d) (cdar d)))))) + ;; Functional update + (define (dict-update d k proc . dfls) + (dict-set d k + (proc (apply dict-ref d k dfls)))) + ;; Performs self-tests of the dictionary module. (define (dictionary-tests!) (run-tests