开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜