Better subsequence support
Closed this issue · 0 comments
I've been asked several times for how to use parse
on a part of an existing vector ala :start
/:end
can do with CL functions like find
.
While jzon
works with displaced arrays for this purpose, they have the downsides of
- being incredibly unergonomic to construct: `(make-array (- (length array) start-offset) :element-type (array-element-type array) :displaced-to array :displaced-index-offset start-offset)
- bringing a performance penalty on access
I'd like to address this somehow. The options I can think of atm are:
- Add
:start
/:end
tojzon:parse
andjzon:make-parser
- Add a
jzon:span
function to represent 'spans' of a sequence using an dedicatedjzon
data type - Add a
jzon:span
function to construct a displaced array for the user in a less painful way
Design-wise, I'm opposed to 1 on the basis that this argument only makes sense for a subset of inputs to parse
and friends, and I'd like to further expand the inputs permitted in the future
From the perspective of the API, 2 and 3 are equivalent as the user sees the same: (jzon:parse (jzon:span seq :start 5 :end 10))
.
Where the differences are more significant is that with 3, if we want to be fully compliant with the spec, there's not much room for optimization in the jzon:reader
interface because technically the user could modify the input vector while reading.
That said, this is such an edge-case, that if a user encounters this issue it may be better to deal with it then and there.
I'm leaning on 2 to be conservative and future proof.