Clojure style hash table syntax for common lisp.
;;; helper function
(defun make-pairs (lst)
(cond ((null lst) lst)
(t (cons (list (first lst) (second lst)) (make-pairs (cddr lst))))))
;; convert a list into a hash
(defun list-to-hash (lst)
(let ((hash (make-hash-table :test #'equal)))
(dolist (x (make-pairs lst) hash)
(destructuring-bind (key value) x
(setf (gethash key hash) value)))))
(defun read-hash (stream char)
"function to be called when the reader sees '{'"
(list-to-hash (read-delimited-list #} stream t)))
;; macro making code
(set-macro-character #{ #'read-hash)
(set-macro-character #} (get-macro-character #)))
Does not support the options that make hash table supports and also, as you can see, my implementation uses ‘equal’ for testing the key instead of using ‘eql’.
CL-USER> { :a 1 :b 2 :c 3 }
#<HASH-TABLE :TEST EQUAL :COUNT 3 {B13BB81}>
CL-USER>
The point of this exercise is not to introduce extra syntax into common lisp, but to show how easy it is to do it in lisp.