summaryrefslogtreecommitdiff
path: root/util/table.scm
blob: efb9613cb326d57a4bb9d7a1e4719e46103f0449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(define-module (util/table)
               #: export (make-table
                           lookup
                           table-insert!))

(define (make-table)
  (list '*table*))

(define (key-assoc key records)
  (cond
    [(null? records) #f]
    [(equal? key (caar records)) (car records)]
    [else (key-assoc key (cdr records))]))

(define (lookup key table)
  (let ([r (key-assoc key (cdr table))])
    (if r
        (cdr r)
        #f)))

(define (table-insert! key value table)
  (let ([r (key-assoc key (cdr table))])
    (if r
        (set-cdr! r value)
        (set-cdr! table (cons (cons key value)
                              (cdr table))))))