Add a few new functions, update docs.
This commit is contained in:
parent
19a3a3b586
commit
a1622048d0
|
@ -68,7 +68,7 @@ of the result</li>
|
||||||
alist of <code>(key . value)</code> pairs.</li>
|
alist of <code>(key . value)</code> pairs.</li>
|
||||||
<li><code>alist-to-hash-table</code>: converts an alist to a hash
|
<li><code>alist-to-hash-table</code>: converts an alist to a hash
|
||||||
table.</li>
|
table.</li>
|
||||||
<li><code>enable-hash-table-reader</code>: Enables the reader
|
<li><code>enable-hash-table-reader</code>: enables the reader
|
||||||
macro <code>#{}#</code> for hash tables. The resulting hash-table
|
macro <code>#{}#</code> for hash tables. The resulting hash-table
|
||||||
will use #'equal for equality. For example,
|
will use #'equal for equality. For example,
|
||||||
|
|
||||||
|
@ -81,6 +81,19 @@ and <code>:c</code>. <code>:a</code> stores the value <code>:b</code>,
|
||||||
and <code>:c</code> stores the value <code>:d</code>.</li>
|
and <code>:c</code> stores the value <code>:d</code>.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<h3>Miscellaneous</h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>interpose</code>: places a separator between each element
|
||||||
|
of a list.</li>
|
||||||
|
<li><code>build-list</code>: if arg is an atom, return it as a
|
||||||
|
list. If it's a list, return the arg. If it's a vector, coerce it
|
||||||
|
to a list. Otherwise, return nil.</li>
|
||||||
|
<li><code>partial</code>: provides partial function application. It
|
||||||
|
returns a lambda that will call the function given with the intial
|
||||||
|
args and any additional args provided to the lambda.</li>
|
||||||
|
<li><code>macroexpand-n</code>: expand the macro n times.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h3>Quicklisp installation</h3>
|
<h3>Quicklisp installation</h3>
|
||||||
|
|
||||||
<p>Clone into your Quicklisp project's <code>local-projects/</code>
|
<p>Clone into your Quicklisp project's <code>local-projects/</code>
|
||||||
|
|
50
kutils.lisp
50
kutils.lisp
|
@ -6,11 +6,12 @@
|
||||||
|
|
||||||
;;; This file contains various utilities I've written.
|
;;; This file contains various utilities I've written.
|
||||||
|
|
||||||
(defun join (x sep)
|
(defun interpose (x sep)
|
||||||
(flatten
|
"Takes a list and a separator, and places separator between element
|
||||||
(mapcar (lambda (y)
|
of the list."
|
||||||
(list y sep))
|
(mapcar (lambda (y)
|
||||||
x)))
|
(list y sep))
|
||||||
|
x))
|
||||||
|
|
||||||
(defun build-list (arg)
|
(defun build-list (arg)
|
||||||
"If arg is an atom, return it as a list. If it's a list, return the
|
"If arg is an atom, return it as a list. If it's a list, return the
|
||||||
|
@ -28,8 +29,21 @@ additional args provided to the lambda."
|
||||||
(lambda (&rest args)
|
(lambda (&rest args)
|
||||||
(apply fn (append initial-args args))))
|
(apply fn (append initial-args args))))
|
||||||
|
|
||||||
|
(defun macroexpand-n (n form)
|
||||||
|
"Expand the macro n times."
|
||||||
|
(let ((new-form form))
|
||||||
|
(dotimes (i n)
|
||||||
|
(multiple-value-bind
|
||||||
|
(expansion expanded)
|
||||||
|
(macroexpand-1 new-form)
|
||||||
|
(if expanded
|
||||||
|
(setf new-form expansion)
|
||||||
|
(return))))
|
||||||
|
new-form))
|
||||||
|
|
||||||
;;; hash-table functions.
|
;;; hash-table functions.
|
||||||
|
|
||||||
|
|
||||||
(defun |#{-reader| (stream sub-char numarg)
|
(defun |#{-reader| (stream sub-char numarg)
|
||||||
(declare (ignore sub-char numarg))
|
(declare (ignore sub-char numarg))
|
||||||
(let ((m (make-hash-table :test 'equal))
|
(let ((m (make-hash-table :test 'equal))
|
||||||
|
@ -39,19 +53,19 @@ additional args provided to the lambda."
|
||||||
(labels ((finalise-read (x)
|
(labels ((finalise-read (x)
|
||||||
(reverse (concatenate 'string x)))
|
(reverse (concatenate 'string x)))
|
||||||
(finalise-kv-pair ()
|
(finalise-kv-pair ()
|
||||||
(if key-p
|
(if key-p
|
||||||
(unless (null k)
|
(unless (null k)
|
||||||
(setq key-p nil
|
(setq key-p nil
|
||||||
k (read-from-string (finalise-read k))))
|
k (read-from-string (finalise-read k))))
|
||||||
(unless (null v)
|
(unless (null v)
|
||||||
(setq key-p t
|
(setq key-p t
|
||||||
v (read-from-string (finalise-read v)))
|
v (read-from-string (finalise-read v)))
|
||||||
(setf (gethash k m) v)
|
(setf (gethash k m) v)
|
||||||
(setq k nil v nil))))
|
(setq k nil v nil))))
|
||||||
(reading-complete-p ()
|
(reading-complete-p ()
|
||||||
(and (null v)
|
(and (null v)
|
||||||
(not
|
(not
|
||||||
(null k)))))
|
(null k)))))
|
||||||
(do ((prev (read-char stream) curr)
|
(do ((prev (read-char stream) curr)
|
||||||
(curr (read-char stream) (read-char stream)))
|
(curr (read-char stream) (read-char stream)))
|
||||||
((and (char= prev #\}) (char= curr #\#)))
|
((and (char= prev #\}) (char= curr #\#)))
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#:join ; My utilities
|
#:join ; My utilities
|
||||||
#:build-list
|
#:build-list
|
||||||
#:partial
|
#:partial
|
||||||
|
#:macroexpand-n
|
||||||
|
#:count-macroexpansions
|
||||||
#:enable-hash-table-reader
|
#:enable-hash-table-reader
|
||||||
#:hashkeys
|
#:hashkeys
|
||||||
#:sethash
|
#:sethash
|
||||||
|
|
Loading…
Reference in New Issue