-
Notifications
You must be signed in to change notification settings - Fork 2
/
database.scm
30 lines (30 loc) · 989 Bytes
/
database.scm
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
27
28
29
30
(require 'schelog)
(module database (%userdb %user-list read-db)
(import chicken scheme extras readline schelog)
(define %userdb %empty-rel)
(define %user-list '())
(set! *schelog-use-occurs-check?* #t)
(define (read-db filename)
(define (read-a-list filename)
(call-with-input-file filename
(lambda (k) (read k))))
(define foldl (lambda (fx acc ls)
(if (null? ls)
acc
(foldl fx (fx acc (car ls)) (cdr ls)))))
(set! %userdb %empty-rel)
(let ((fun (lambda (ls) (eval (list '%assert '%userdb '() ls))))
(template (cdr (read-a-list filename)))
(check-db (lambda (ls mem)
(if (member (cadaar mem) ls) (begin
(display "[WARNING!] Duplicated entries for user: ")
(display (cadaar mem))
(newline)
ls)
(cons (cadaar mem) ls)))))
(display "[ADDED] ")
(display (reverse (foldl check-db '() template)))
(set! %user-list (reverse (foldl check-db '() template)))
(newline)
(map fun template)))
)