4 ms·
Lisp especially is built upon linked lists, which have different costs for (more or less) primitive operations (add to the front, get the front item, get a rest
by lispm 4y ago
Lisp especially is built upon linked lists, which have different costs for (more or less) primitive operations (add to the front, get the front item, get a rest list, get a random element, add to the end, ...) compare to a primitive vector. There are also other features not easily replicated by vectors.
CL-USER 40 > (rest '(1 2 3))
(2 3)
Above REST operation does not allocate any memory.
CL-USER 41 > (subseq '#(1 2 3) 1)
#(2 3)
Above SUBSEQ returns a new vector. Alternatively it would need a more clever implementation underneath.
OTOH getting a random element has a different complexity in a linked list vs. a vector.