Docs and a few tweaks.
This commit is contained in:
parent
27dc152240
commit
89c94158c2
45
README.txt
45
README.txt
|
@ -1 +1,44 @@
|
||||||
This is the stub README.txt for the "kutils" project.
|
KUTILS
|
||||||
|
|
||||||
|
This is a collection of Kyle's utilities. They're things that I find
|
||||||
|
generally useful when writing programs.
|
||||||
|
|
||||||
|
There's a few groups of tools:
|
||||||
|
|
||||||
|
* Functions from On Lisp
|
||||||
|
* Functions and macros from Let Over Lambda
|
||||||
|
* Hash-table based functions
|
||||||
|
* Miscellaneous
|
||||||
|
|
||||||
|
On Lisp tools
|
||||||
|
=============
|
||||||
|
|
||||||
|
* mkstr
|
||||||
|
* symb
|
||||||
|
* group
|
||||||
|
* flatten
|
||||||
|
* compose
|
||||||
|
|
||||||
|
Let Over Lambda
|
||||||
|
===============
|
||||||
|
|
||||||
|
* defmacro!
|
||||||
|
|
||||||
|
Hash-table
|
||||||
|
==========
|
||||||
|
|
||||||
|
* hashkeys
|
||||||
|
* sethash
|
||||||
|
* hash-table-to-alist
|
||||||
|
* alist-to-hash-table
|
||||||
|
|
||||||
|
The function `enable-hashtable-reader` will activate a reader macro
|
||||||
|
for hash-tables using `:test #'equal`. This syntax looks like
|
||||||
|
|
||||||
|
#{ k v ... }#
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
CL-USER> (kutils:hashkeys (kutils:alist-to-hashtable (kutils:hashtable-to-alist #{:a :b :c :d}#)))
|
||||||
|
(:A :C)
|
||||||
|
|
||||||
|
|
13
kutils.lisp
13
kutils.lisp
|
@ -51,7 +51,7 @@
|
||||||
(finalise-kv-pair)
|
(finalise-kv-pair)
|
||||||
m)))))
|
m)))))
|
||||||
|
|
||||||
(defun enable-hashtable-literal ()
|
(defun enable-hash-table-reader ()
|
||||||
"Enables the reader macro #{}# for hash-tables. The resulting
|
"Enables the reader macro #{}# for hash-tables. The resulting
|
||||||
hash-table will use #'equal for equality. For example,
|
hash-table will use #'equal for equality. For example,
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ value :b, and :c stores the value :d.
|
||||||
m)
|
m)
|
||||||
keys))
|
keys))
|
||||||
|
|
||||||
(defun hashtable-to-alist (m)
|
(defun hash-table-to-alist (m)
|
||||||
"Converts the hash-table given to an alist of (key . value) pairs."
|
"Converts the hash-table given to an alist of (key . value) pairs."
|
||||||
(let ((alist '()))
|
(let ((alist '()))
|
||||||
(maphash (lambda (k v)
|
(maphash (lambda (k v)
|
||||||
|
@ -84,3 +84,12 @@ value :b, and :c stores the value :d.
|
||||||
(setf alist (cons elt alist))))
|
(setf alist (cons elt alist))))
|
||||||
m)
|
m)
|
||||||
alist))
|
alist))
|
||||||
|
|
||||||
|
(defun alist-to-hash-table (alist)
|
||||||
|
"Converts the alist to a hash-table."
|
||||||
|
(let ((m (make-hash-table :test 'equal)))
|
||||||
|
(dolist (elt alist)
|
||||||
|
(sethash (car elt) (cdr elt) m))
|
||||||
|
m))
|
||||||
|
|
||||||
|
(defun kget (elt indicator)
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
#:compose
|
#:compose
|
||||||
#:defmacro! ; Let Over Lambda utilities
|
#:defmacro! ; Let Over Lambda utilities
|
||||||
#:join ; My utilities
|
#:join ; My utilities
|
||||||
|
#:enable-hash-table-reader
|
||||||
|
#:hashkeys
|
||||||
#:sethash
|
#:sethash
|
||||||
|
#:hash-table-to-alist
|
||||||
|
#:alist-to-hash-table
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue