all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Defining new sequence types for seq.el
@ 2019-11-12  0:43 Eric Abrahamsen
  2019-11-12  3:02 ` Juanma Barranquero
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Abrahamsen @ 2019-11-12  0:43 UTC (permalink / raw)
  To: emacs-devel

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?

Thanks,
Eric




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-13  1:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-12  0:43 Defining new sequence types for seq.el Eric Abrahamsen
2019-11-12  3:02 ` Juanma Barranquero
2019-11-13  0:16   ` Eric Abrahamsen
2019-11-13  1:04     ` Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.