summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2022-10-31 19:39:43 +0100
committerLeah Neukirchen <leah@vuxu.org>2022-10-31 19:39:43 +0100
commit490d0fe8914cb5674c9ae3dd491b98c25fbff3b6 (patch)
treed349bc64fadcea3afb33afbecfa847c1302e5c0e
parent6fa0ea62fba63cda1da1992099f87a659d8d130a (diff)
downloadmew-490d0fe8914cb5674c9ae3dd491b98c25fbff3b6.tar.gz
mew-490d0fe8914cb5674c9ae3dd491b98c25fbff3b6.tar.xz
mew-490d0fe8914cb5674c9ae3dd491b98c25fbff3b6.zip
add set-at, del-at
-rw-r--r--mew.scm22
-rw-r--r--mew.svnwiki10
2 files changed, 31 insertions, 1 deletions
diff --git a/mew.scm b/mew.scm
index ec27927..b678bb9 100644
--- a/mew.scm
+++ b/mew.scm
@@ -243,7 +243,7 @@
           ((vector? o) (vector-set! o k v))
           ((hash-table? o) (hash-table-set! o k v))
           ((string? o) (string-set! o k v))
-          (#t (error "not set for at defined"))))
+          (#t (error "no set for at defined"))))
 
   (define at (getter-with-setter get get-setter))
 
@@ -257,6 +257,26 @@
   (define (tbl . kvs)
     (alist->hash-table (kvs->alist kvs)))
 
+  (define (set-at o . rest)
+    (cond ((hash-table? o) (for-each (lambda (kv)
+                                       (hash-table-set! o (car kv) (cdr kv)))
+                                     (kvs->alist rest)))
+          ((vector? o)     (for-each (lambda (kv)
+                                       (vector-set! o (car kv) (cdr kv)))
+                                     (kvs->alist rest)))
+          ((string? o)     (for-each (lambda (kv)
+                                       (string-set! o (car kv) (cdr kv)))
+                                     (kvs->alist rest)))
+          (else            (error "no set-at defined")))
+    o)
+
+  (define (del-at o . rest)
+    (cond ((hash-table? o) (for-each (lambda (k)
+                                       (hash-table-delete! o k))
+                                     rest))
+          (else            (error "no del-at defined")))
+    o)
+
   (define (empty? o)
     (or (null? o)
         (equal? o "")
diff --git a/mew.svnwiki b/mew.svnwiki
index 378e87c..ef27a3f 100644
--- a/mew.svnwiki
+++ b/mew.svnwiki
@@ -198,6 +198,16 @@ Return true if all values are pairwise different.
 Generalized accessor, supports indexing into lists, vectors,
 hash-tables, strings.
 
+<procedure>(set-at <obj> <key1> <val1>...)</procedure>
+
+Mutate the hash-table/vector/string {{<obj>}} by setting
+the key/index {{<key1>}} to {{<val1>}} etc.
+Returns {{<obj>}}.
+
+<procedure>(del-at <hash-table> <key>...)</procedure>
+
+Delete {{<key>}} from the hash-table, and return the hash-table.
+
 <procedure>(tbl <key1> <val1> ... <keyN> <valN>)</procedure>
 
 Construct a hash-table; using {{equal?}}.