You can programmatically build a hash table while reading:
(defvar *ht*
(loop for (key . value) in
'((a . 1) (b . 2) (c . 3))
do (setf (gethash key ht) value))
ht))
(describe *ht*)
#.used to estimate reading time. Then the compiler will output the hash table to the FASL file.
This can then be compiled:
Using SBCL:
* (compile-file "/tmp/test.lisp")
; compiling file "/private/tmp/test.lisp" (written 24 MAY 2012 10:08:49 PM):
; compiling (DEFVAR *HT* ...)
; compiling (DESCRIBE *HT*)
; /tmp/test.fasl written
; compilation finished in 0:00:00.360
NIL
NIL
* (load *)
[hash-table]
Occupancy: 0.2
Rehash-threshold: 1.0
Rehash-size: 1.5
Size: 16
Synchronized: no
T
* *ht*
Creating a hash table as a function:
(defun create-hashtable (alist
&key (test 'eql)
&aux (ht (make-hash-table :test test)))
(loop for (key . value) in alist
do (setf (gethash key ht) value))
ht)
source
share