diff --git a/README.txt b/README.txt index 975733f..cec3089 100644 --- a/README.txt +++ b/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) + diff --git a/kutils.lisp b/kutils.lisp index 260214f..8d3785d 100644 --- a/kutils.lisp +++ b/kutils.lisp @@ -51,7 +51,7 @@ (finalise-kv-pair) m))))) -(defun enable-hashtable-literal () +(defun enable-hash-table-reader () "Enables the reader macro #{}# for hash-tables. The resulting hash-table will use #'equal for equality. For example, @@ -76,7 +76,7 @@ value :b, and :c stores the value :d. m) keys)) -(defun hashtable-to-alist (m) +(defun hash-table-to-alist (m) "Converts the hash-table given to an alist of (key . value) pairs." (let ((alist '())) (maphash (lambda (k v) @@ -84,3 +84,12 @@ value :b, and :c stores the value :d. (setf alist (cons elt alist)))) m) 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) diff --git a/package.lisp b/package.lisp index 8ff12f3..7433a05 100644 --- a/package.lisp +++ b/package.lisp @@ -9,6 +9,9 @@ #:compose #:defmacro! ; Let Over Lambda utilities #:join ; My utilities + #:enable-hash-table-reader + #:hashkeys #:sethash + #:hash-table-to-alist + #:alist-to-hash-table )) -