What's the relationship between vector and list in Lisp?
I was told that there are only atom and list as the basic data structure in Lisp, does this mean vector in Lisp is some type of list? Was vector stored as list in the underl开发者_JAVA百科ying?
What you were told was accurate but might not have been the clearest description.
In Common Lisp, at least:
* (type-of #(3 4 5))
(SIMPLE-VECTOR 3)
* (atom #(3 4 5))
T
An atom is defined as anything which is not a CONS cell -- including vectors, class instances, and so on. So yes, a vector is officially considered an "atom" in Lisp, which is why you were told what you were told.
As everywhere else vector
is structure for efficient random access, usually wrapper around array with some extras (auto grow). List is best for sequentical access and fast insertion.
精彩评论