From 45ef5eddb4a34a5e3e125274e3eabc840036864c Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 6 Apr 2015 10:50:07 -0700 Subject: [PATCH] Require explicit enabling of hash-table reader macro. --- kutils.lisp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kutils.lisp b/kutils.lisp index 30c15e3..52154b6 100644 --- a/kutils.lisp +++ b/kutils.lisp @@ -30,7 +30,11 @@ (setq key-p t v (read-from-string (finalise-read v))) (setf (gethash k m) v) - (setq k nil v nil))))) + (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 #\#))) @@ -39,14 +43,15 @@ (if key-p (push prev k) (push prev v)))) - (if (and (null v) (not (null k))) + (if (reading-complete-p) (error "Mismatched key value pairs.") (progn (finalise-kv-pair) m))))) -(set-dispatch-macro-character - #\# #\{ #'|#{-reader|) +(defun enable-hashtable-literal () + (set-dispatch-macro-character + #\# #\{ #'|#{-reader|)) (defun sethash (k v m) "Convenience notation for setting a value in a hash table."