From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Defining new sequence types for seq.el Date: Mon, 11 Nov 2019 16:43:58 -0800 Message-ID: <871rud3ovl.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="129225"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 12 01:44:41 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iUKIR-000XTl-C6 for ged-emacs-devel@m.gmane.org; Tue, 12 Nov 2019 01:44:39 +0100 Original-Received: from localhost ([::1]:58304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUKIQ-0000Mn-1M for ged-emacs-devel@m.gmane.org; Mon, 11 Nov 2019 19:44:38 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54749) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUKHz-0000MV-CB for emacs-devel@gnu.org; Mon, 11 Nov 2019 19:44:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUKHy-0006cR-Bx for emacs-devel@gnu.org; Mon, 11 Nov 2019 19:44:11 -0500 Original-Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:52460 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUKHy-0006bl-5R for emacs-devel@gnu.org; Mon, 11 Nov 2019 19:44:10 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iUKHv-000WxS-GC for emacs-devel@gnu.org; Tue, 12 Nov 2019 01:44:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:MvBV6Ig7BPWWZgRJVCo07/tQZqo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:242097 Archived-At: 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