3 ms·
> the same first/next semantics and performance as lists How so? Say we have a vector #(1 2 3 4) . How do I get a vector with the first element removed? How
by lispm 4y ago
> the same first/next semantics and performance as lists
How so?
Say we have a vector #(1 2 3 4) .
How do I get a vector with the first element removed? How do I get a vector with a element added?
(rest #(1 2 3 4)) -> #(2 3 4)
(prepend 0 #(1 2 3 4)) -> #(0 1 2 3 4)
There are basically a few options to implement this:
a) allocate new vectors
b) implement growing/shrinking vectors
c) do something very clever internally, sharing vector memory
With cons cells this is simple. The possible drawbacks:
a) memory is fragmented into cons cells linking each other
b) lists may share memory