diff options
Diffstat (limited to 'util/table.scm')
-rw-r--r-- | util/table.scm | 21 |
1 files changed, 21 insertions, 0 deletions
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)))))) | ||