Can you have hash tables or dicts in Lisp? I mean the data structure that is a collection of pairs (key, value) where values can be acceded using keys.
Common Lisp has at least four different ways to do that (key value storage):
For simple usage assoc lists or property lists are fine. With a larger number of elements they tend to get 'slow'. Hash tables are 'faster' but have their own tradeoffs. CLOS objects are used like in many other object systems. The keys are the slot-names defined in a CLOS class. Though it is possible to program variants that can add and remove slots on access.
If you're referring to Common Lisp, hash tables are provided by a type called hash-table
.
Using these tables involves creating one with function make-hash-table
, reading values with gethash
, setting them by using gethash
as a place in concert with setf
, and removing entries with remhash
.
The mapping from key value to hash code is available outside of hash tables with the function sxhash
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With