From c93d192c32c376705d3b0a740c81156a44e63ecb Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 4 Nov 2020 08:53:43 +0530 Subject: add basic evaluator, environment --- util/alist.scm | 12 ++++++++++++ util/table.scm | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 util/alist.scm create mode 100644 util/table.scm (limited to 'util') 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 @@ +(define (is-elem-assoc-list key assoc-list) + (cond + [(null? assoc-list) #f] + [(eq? key (caar assoc-list)) #t] + [else (lookup-assoc-list key (cdr assoc-list))])) + +(define (lookup-assoc-list key assoc-list) + (cond + [(null? assoc-list) #f] + [(eq? key (caar assoc-list)) (cdar assoc-list)] + [else (lookup-assoc-list key (cdr assoc-list))])) + 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 @@ +(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)))))) -- cgit v1.2.3