summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-11-04 03:23:43 +0000
committerAkshay <[email protected]>2020-11-04 03:23:43 +0000
commitc93d192c32c376705d3b0a740c81156a44e63ecb (patch)
tree8b25ec67c7c1f857d598d383537283e086017e88 /util
parent893980d4e5d3e698bed652fbfb021b128a5d6b3c (diff)
add basic evaluator, environment
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))))))