Add a few new functions, update docs.

This commit is contained in:
Kyle Isom 2015-04-08 14:01:15 -07:00
parent 19a3a3b586
commit a1622048d0
3 changed files with 48 additions and 19 deletions

View File

@ -68,7 +68,7 @@ of the result</li>
alist of <code>(key . value)</code> pairs.</li>
<li><code>alist-to-hash-table</code>: converts an alist to a hash
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
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>
</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>
<p>Clone into your Quicklisp project's <code>local-projects/</code>

View File

@ -6,11 +6,12 @@
;;; This file contains various utilities I've written.
(defun join (x sep)
(flatten
(defun interpose (x sep)
"Takes a list and a separator, and places separator between element
of the list."
(mapcar (lambda (y)
(list y sep))
x)))
x))
(defun build-list (arg)
"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)
(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.
(defun |#{-reader| (stream sub-char numarg)
(declare (ignore sub-char numarg))
(let ((m (make-hash-table :test 'equal))

View File

@ -11,6 +11,8 @@
#:join ; My utilities
#:build-list
#:partial
#:macroexpand-n
#:count-macroexpansions
#:enable-hash-table-reader
#:hashkeys
#:sethash