From a1622048d0c1f5f0bcde673281c1391a9859ff53 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 8 Apr 2015 14:01:15 -0700 Subject: [PATCH] Add a few new functions, update docs. --- doc/index.html | 15 ++++++++++++++- kutils.lisp | 50 ++++++++++++++++++++++++++++++++------------------ package.lisp | 2 ++ 3 files changed, 48 insertions(+), 19 deletions(-) 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.
  • +

    Miscellaneous

    + +

    Quicklisp installation

    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