你可以在lisp中有哈希表吗? [英] Can you have hash tables in lisp?
问题描述
Lisp至少有四种不同的方式来实现(键值存储):
- 属性列表(:foo 1:bar 2) li>
- assoc list((:foo。1)(:bar。2))
- 哈希表
- CLOS要获取的对象(slot-value foo'bar)和(setf(slot-value foo'bar))设置。插槽名称可以存储在一个变量中:(let((name'bar))(slot-value foo name))
对于简单的使用列表或属性列表是罚款。随着元素数量的增加,他们往往会变得慢。哈希表是更快,但有自己的权衡。像许多其他对象系统一样使用CLOS对象。键是在CLOS类中定义的插槽名称。虽然可以对可以在访问中添加和删除插槽的变体进行编程。
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):
- property lists (:foo 1 :bar 2)
- assoc lists ((:foo . 1) (:bar . 2))
- hash tables
- CLOS objects (slot-value foo 'bar) to get and (setf (slot-value foo 'bar) 42) to set. The slot name can be stored in a variable: (let ((name 'bar)) (slot-value foo name)) .
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.
这篇关于你可以在lisp中有哈希表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!