summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/alist.scm12
-rw-r--r--util/table.scm21
2 files changed, 33 insertions, 0 deletions
diff --git a/util/alist.scm b/util/alist.scm
new file mode 100644
index 0000000..4e19440
--- /dev/null
+++ b/util/alist.scm
@@ -0,0 +1,12 @@
1(define (is-elem-assoc-list key assoc-list)
2 (cond
3 [(null? assoc-list) #f]
4 [(eq? key (caar assoc-list)) #t]
5 [else (lookup-assoc-list key (cdr assoc-list))]))
6
7(define (lookup-assoc-list key assoc-list)
8 (cond
9 [(null? assoc-list) #f]
10 [(eq? key (caar assoc-list)) (cdar assoc-list)]
11 [else (lookup-assoc-list key (cdr assoc-list))]))
12
diff --git a/util/table.scm b/util/table.scm
new file mode 100644
index 0000000..7cc68e8
--- /dev/null
+++ b/util/table.scm
@@ -0,0 +1,21 @@
1(define (make-table)
2 (list '*table*))
3
4(define (key-assoc key records)
5 (cond
6 [(null? records) #f]
7 [(equal? key (caar records)) (car records)]
8 [else (key-assoc key (cdr records))]))
9
10(define (lookup key table)
11 (let ([r (key-assoc key (cdr table))])
12 (if r
13 (cdr r)
14 #f)))
15
16(define (table-insert! key value table)
17 (let ([r (key-assoc key (cdr table))])
18 (if r
19 (set-cdr! r value)
20 (set-cdr! table (cons (cons key value)
21 (cdr table))))))