diff options
| author | Mistivia <i@mistivia.com> | 2024-02-25 20:11:54 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2024-02-25 20:11:54 +0800 |
| commit | 515ecbf5a20a8e432a998b0a543bedcb1bd64cf4 (patch) | |
| tree | 6353c603a8cf0276553f420205f8d1c730a318ce /lib/obj.rkt | |
| parent | e191b610c11326b587cf0b01fd6fc37b8d07bb19 (diff) | |
reorg code
Diffstat (limited to 'lib/obj.rkt')
| -rw-r--r-- | lib/obj.rkt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/obj.rkt b/lib/obj.rkt new file mode 100644 index 0000000..8ffc401 --- /dev/null +++ b/lib/obj.rkt @@ -0,0 +1,32 @@ +#lang racket + +(provide obj-maker + obj-set + obj-show) + +(define (alist->obj alist) + (λ key + (if (null? key) + alist + (cadr (assoc (car key) alist))))) + +(define (obj-maker . fields) + (λ inits + (define alist (map list fields inits)) + (alist->obj alist))) + +(define (obj-set record key value) + (define alist (record)) + (define new-alist + (let loop ((new-list '()) (cur alist) (is-set #f)) + (if (null? cur) + (if is-set + new-list + (cons (list key value) new-list)) + (let () + (if (eq? key (caar cur)) + (loop (cons (list key value) new-list) (cdr cur) #t) + (loop (cons (car cur) new-list) (cdr cur) is-set)))))) + (alist->obj new-alist)) + +(define (obj-show x) (x))
\ No newline at end of file |
