Can you have hash tables or dicts in Lisp? I mean a data structure, which is a set of pairs (key, value), where values can be attached using keys.
Generic Lisp have at least four different ways to do this (storing key values):
For simple use lists or property lists in order. With a lot of elements, they tend to become "slow." Hash tables are faster, but have their own tradeoffs. CLOS objects are used, as in many other object systems. The keys are the slot names defined in the CLOS class. Although you can program options that can add and remove slots at access.
If you reference Common Lisp hash tables , you get a hash-table .
hash-table
Using these tables involves creating with the make-hash-table function, counting the gethash values, setting them, using gethash as place in conjunction with setf and deleting the entries from remhash .
make-hash-table
gethash
setf
remhash
Mapping from the key value to the hash code is available outside the hash tables using the sxhash function.
sxhash
Of course - Common Lisp has hash tables .
(setq a (make-hash-table)) (setf (gethash 'color a) 'brown) (setf (gethash 'name a) 'fred) (gethash 'color a) => brown (gethash 'name a) => fred (gethash 'pointy a) => nil
Property lists are good for very small examples of demonstrative purpose, but for any real need, their performance is terrible, so use hash tables.
Clojure has a built-in card type:
user=> (def m {:foo "bar" :baz "bla"}) #'user/m user=> (m :foo) "bar"
See http://clojure.org/data_structures
Of course. Here's the SRFI that defines the standard hash table libraries in the Schema:
http://srfi.schemers.org/srfi-69/srfi-69.html
It has built- in ones that use a system hash function (usually SXHASH) and where you can have a couple of different checker equalities (EQ, EQL, EQUAL or EQUALP depending on what you consider to be "the same").
If the built-in hash tables are not good enough, there is also a common hash table . It will take any pair of “hash generator” / “key comparator” and build a hash table for you. However, it relies on a good hash function, and this is not necessarily trivial to write.
In Lisp, it is usually called a property list.