diff --git a/doc/index.html b/doc/index.html
index 5bbc39c..77ea117 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -68,7 +68,7 @@ of the result
alist of (key . value)
pairs.
alist-to-hash-table
: converts an alist to a hash
table.enable-hash-table-reader
: Enables the reader
+ enable-hash-table-reader
: enables the reader
macro #{}#
for hash tables. The resulting hash-table
will use #'equal for equality. For example,
@@ -81,6 +81,19 @@ and :c
. :a
stores the value :b
,
and :c
stores the value :d
.interpose
: places a separator between each element
+ of a list.build-list
: 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.partial
: 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.macroexpand-n
: expand the macro n times.Clone into your Quicklisp project's local-projects/
diff --git a/kutils.lisp b/kutils.lisp
index b3861db..85ab14d 100644
--- a/kutils.lisp
+++ b/kutils.lisp
@@ -6,11 +6,12 @@
;;; This file contains various utilities I've written.
-(defun join (x sep)
- (flatten
- (mapcar (lambda (y)
- (list y sep))
- x)))
+(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))
(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))
@@ -39,19 +53,19 @@ additional args provided to the lambda."
(labels ((finalise-read (x)
(reverse (concatenate 'string x)))
(finalise-kv-pair ()
- (if key-p
- (unless (null k)
- (setq key-p nil
- k (read-from-string (finalise-read k))))
- (unless (null v)
- (setq key-p t
- v (read-from-string (finalise-read v)))
- (setf (gethash k m) v)
- (setq k nil v nil))))
- (reading-complete-p ()
- (and (null v)
- (not
- (null k)))))
+ (if key-p
+ (unless (null k)
+ (setq key-p nil
+ k (read-from-string (finalise-read k))))
+ (unless (null v)
+ (setq key-p t
+ v (read-from-string (finalise-read v)))
+ (setf (gethash k m) v)
+ (setq k nil v nil))))
+ (reading-complete-p ()
+ (and (null v)
+ (not
+ (null k)))))
(do ((prev (read-char stream) curr)
(curr (read-char stream) (read-char stream)))
((and (char= prev #\}) (char= curr #\#)))
diff --git a/package.lisp b/package.lisp
index fb5b49c..1a32c16 100644
--- a/package.lisp
+++ b/package.lisp
@@ -11,6 +11,8 @@
#:join ; My utilities
#:build-list
#:partial
+ #:macroexpand-n
+ #:count-macroexpansions
#:enable-hash-table-reader
#:hashkeys
#:sethash