- Reader macro
The package has an optional reader macro that attempts to make Clojure-like hash table literals in the reader. For example:
CL-USER> (gethash :foo #{:foo :bar :baz :quux}#) :BAR T CL-USER> (let ((m #{:foo :bar :baz :quux}#)) (sethash :baz :woz m) (hashkeys m)) (:BAZ :FOO) CL-USER> (hashtable-to-alist #{:a :b :c :d}#) ((:C . :D) (:A . :B))
enable-hash-table-reader
nil
Enables the reader macro
#{}#
for hash-tables. The resulting hash-table will use#'equal
for equality. For example,#{:a :b :c :d}#
will create a hash-table with the keys
:a
and:c
; :a
stores the value:b
, and:c
stores the value:d
.- Table manipulation
-
hashkeys
(ht)
Returns a list of the keys in a hash table.sethash
(k v ht)
Convenience notation for setting a value in a hash table.new-hash-table
nil
Create a new hash table with the#'equal
function as its test.hash-table-to-alist
(ht)
Converts the hash-table argument to an alist of(key . value)
pairs.copy-hash-table
(ht)
Shallow copyht
. with-new-hash-table
with-new-hash-table
is a convenience macro for creating a new hash table and acting on it.In the simplest case, it takes a single symbol and a body:
* (with-new-hash-table (ht) (sethash "case" '("neuromancer") ht) (sethash "bigend" '("pattern recognition" "spook country" "zero history") ht)) #<HASH-TABLE :TEST EQUAL :COUNT 2 {1009044DC3}>
If more than one symbol is provided, the resulting hash tables will be returned as an alist:
* (with-new-hash-table (neuromancer pattern-recognition) (sethash "places" '("chiba city" "istanbul" "villa straylight") neuromancer) (sethash "places" '("london" "tokyo" "moscow") pattern-recognition)) ((NEUROMANCER . #<HASH-TABLE :TEST EQUAL :COUNT 1 {100959E273}>) (PATTERN-RECOGNITION . #<HASH-TABLE :TEST EQUAL :COUNT 1 {100959E6B3}>))
with-new-hash-table
(htsyms &body body)
Create and bind a new hash table for each of the symbols inhtsyms
, executing inside a let form, and returns the hash table(s). If only one hash table is provided, return it as a single element; otherwise, return an alist of the symbol names and hash tables.