[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Defining new sequence types for seq.el

From: Eric Abrahamsen
Subject: Defining new sequence types for seq.el
Date: Mon, 11 Nov 2019 16:43:58 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

My apologies if I'm missing something very obvious here, but seq.el and
the accompanying documentation mention defining new sequence types, and
I don't actually see how you go about doing that. The library uses
generic functions, so you'd need something that can be specialized on,
but... how?

Say for the sake of argument that I'd like to define a new sequence type
called `gnus-range', which is nothing more than a list of integers, but
where a list like (1 4 5 6 7 12 21 22 23) would be represented as
(1 (4 . 7) 12 (21 . 23)), in order to save space (yes I know that example
doesn't save much space, these are very long lists).

This seems like a great use for the generic functions in seq: for
instance, (seq-elt '((1 . 9) 35 120) 0) could return 1 instead of (1 . 9).

But I don't know how to make the type identifiable to the generic
functions. I tried:

(cl-deftype gnus-range () '(or null cons))

But generic methods don't check deftypes, and also that's the same
definition as for lists, which seems like it could wreak havoc.

Do I need to use a struct with one slot? Any other tips?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]