using stdint types

This commit is contained in:
FelixBrendel
2020-03-31 11:38:53 +02:00
parent 33145be4c6
commit 76dd4d6482
52 changed files with 483 additions and 1503 deletions
+22 -22
View File
@@ -15,13 +15,13 @@
:alist))
(define (print alist)
(let ((associations (first alist)))
(let ((associations (car alist)))
(define (pprint-intern associations)
(when associations
(print " "
(caar associations) "->"
(cdar associations))
(pprint-intern (rest associations))))
(pprint-intern (cdr associations))))
(print "(")
(when associations
(print "\n")
@@ -30,22 +30,22 @@
(define (get alist key)
(let ((associations (first alist)))
(let ((associations (car alist)))
(define (alist-get-intern associations key)
(cond ((null? associations)
(error :key-not-found "key was not found in alist"))
((= (caar associations) key)
(cdar associations))
(else (alist-get-intern (rest associations) key))))
(else (alist-get-intern (cdr associations) key))))
(alist-get-intern associations key)))
(define (find alist key)
(let ((associations (first alist)))
(let ((associations (car alist)))
(define (alist-find-intern associations key current-index)
(cond ((null? associations) key-not-found-index)
((= (caar associations) key) current-index)
(else (alist-find-intern (rest associations)
(else (alist-find-intern (cdr associations)
key
(+ 1 current-index)))))
(alist-find-intern associations key 0)))
@@ -65,31 +65,31 @@
(if (= index 1)
;; we want to remove the next one, so we set our
;; cdr to the next next one
(mutate associations (pair (first associations)
(rest (rest associations))))
(mutate! associations (cons (car associations)
(cdr (cdr associations))))
;; else cdr-recurse
(alist-remove!-internal (rest asociations) (- index 1))))
(alist-remove!-internal (cdr asociations) (- index 1))))
(cond ((= index key-not-found-index) (error :key-not-found "key to remove was not found"))
((= index 0) (mutate alist (pair (cdar alist) ())))
((= index 0) (mutate! alist (cons (cdar alist) ())))
(else (alist-remove!-internal alist index))))
alist)
(define (set! alist key value)
(mutate alist (set-type! (pair (pair (pair key value)
(mutate! alist (set-type! (cons (cons (cons key value)
(car alist))
())
:alist)))
(define (set-overwrite! alist key value)
(let ((associations (first alist)))
(let ((associations (car alist)))
(define (alist-set-overwrite-intern associations key value)
(cond ((= (caar associations) key)
(mutate (car associations) (pair key value)))
(mutate! (car associations) (cons key value)))
((null? associations) (set! alist key value))
(else (alist-set-overwrite-intern
(rest associations) key value))))
(cdr associations) key value))))
(alist-set-overwrite-intern associations key value))
alist)
)
@@ -116,7 +116,7 @@
:plist))
(define (print plist)
(let ((props (first plist)))
(let ((props (car plist)))
(define (pprint-intern props)
(when props
(print " "
@@ -130,7 +130,7 @@
(print ")\n")))
(define (get plist prop)
(let ((props (first plist)))
(let ((props (car plist)))
(define (plist-get-intern props prop)
(cond ((null? props)
(error :key-not-found "property was not found in plist"))
@@ -140,14 +140,14 @@
(plist-get-intern props prop)))
(define (set! plist prop value)
(mutate plist (set-type! (pair (pair prop (pair value (first plist))) ())
(mutate! plist (set-type! (cons (cons prop (cons value (car plist))) ())
:plist)))
(define (set-overwrite! plist prop value)
(let ((props (first plist)))
(let ((props (car plist)))
(define (plist-set-overwrite-intern props prop value)
(cond ((= (car props) prop)
(mutate (cdr props) (pair value (cddr props))))
(mutate! (cdr props) (cons value (cddr props))))
((null? props) (plist-set! plist prop value))
(else (plist-set-overwrite-intern
(cddr props) prop value))))
@@ -155,7 +155,7 @@
plist)
(define (find plist prop)
(let ((props (first plist)))
(let ((props (car plist)))
(define (plist-find-intern props prop current-index)
(cond ((null? props) key-not-found-index)
((= (car props) prop) current-index)
@@ -176,13 +176,13 @@
(if (= index 1)
;; we want to remove the next one, so we set our
;; cdr to the next next one
(mutate (cdar props) (pair (cadar props) ;; xD nice meme dude!!!
(mutate! (cdar props) (cons (cadar props) ;; xD nice meme dude!!!
(cdr (cdr (cdr (cdar props))))))
;; else cdr-recurse
(plist-remove!-internal (cddr props) (- index 1))))
(cond ((= index key-not-found-index) (error :key-not-found "prop to remove was not found"))
((= index 0) (mutate plist (pair (cddar plist) ())))
((= index 0) (mutate! plist (cons (cddar plist) ())))
(else (plist-remove!-internal plist index))))
plist)