aboutsummaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2021-12-06 03:51:00 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2021-12-06 03:51:00 +0100
commit255f16e143c7d91dab61fa36c20b22af1fc06143 (patch)
tree7fdd40eace6fd6cd52ea49263014b905ab2cf430 /module
parentFormatting fixes in make-block. (diff)
downloadcalp-255f16e143c7d91dab61fa36c20b22af1fc06143.tar.gz
calp-255f16e143c7d91dab61fa36c20b22af1fc06143.tar.xz
Add assoc-ref-all family of procedures.
Diffstat (limited to 'module')
-rw-r--r--module/calp/util.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/module/calp/util.scm b/module/calp/util.scm
index 06767658..77dd9316 100644
--- a/module/calp/util.scm
+++ b/module/calp/util.scm
@@ -523,6 +523,21 @@
(call-with-values (lambda () (apply proc args)) list))
lists)))
+(define (ass%-ref-all alist key =)
+ (map cdr (filter (lambda (pair) (= key (car pair)))
+ alist)))
+
+;; Equivalent to assoc-ref (and family), but works on association lists with
+;; non-unique keys, returning all mathing records (instead of just the first).
+;; @begin lisp
+;; (assoc-ref-all '((a . 1) (b . 2) (a . 3)) 'a)
+;; ⇒ (1 3)
+;; @end
+(define-public (assoc-ref-all alist key) (ass%-ref-all alist key equal?))
+(define-public (assq-ref-all alist key) (ass%-ref-all alist key eq?))
+(define-public (assv-ref-all alist key) (ass%-ref-all alist key eqv?))
+
+
(define-public (vector-last v)