From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] sequence manipulation functions Date: Mon, 10 Nov 2014 12:41:47 -0500 Message-ID: References: <87oasmmwzt.fsf@gmail.com> <87bnolslph.fsf@gmail.com> <87zjc2dic0.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1415641369 17690 80.91.229.3 (10 Nov 2014 17:42:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Nov 2014 17:42:49 +0000 (UTC) Cc: Emacs developers To: Nicolas Petton Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 10 18:42:42 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XnszA-0006iP-NE for ged-emacs-devel@m.gmane.org; Mon, 10 Nov 2014 18:42:40 +0100 Original-Received: from localhost ([::1]:44409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XnszA-0003yD-DW for ged-emacs-devel@m.gmane.org; Mon, 10 Nov 2014 12:42:40 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xnsyq-0003xD-7Y for emacs-devel@gnu.org; Mon, 10 Nov 2014 12:42:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xnsyh-0008Pp-VW for emacs-devel@gnu.org; Mon, 10 Nov 2014 12:42:20 -0500 Original-Received: from mercure.iro.umontreal.ca ([132.204.24.67]:38828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xnsyh-0008Pi-QT for emacs-devel@gnu.org; Mon, 10 Nov 2014 12:42:11 -0500 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id 2C95B84F9A; Mon, 10 Nov 2014 12:42:11 -0500 (EST) Original-Received: from lechon.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id E0CB11E5B8A; Mon, 10 Nov 2014 12:41:47 -0500 (EST) Original-Received: by lechon.iro.umontreal.ca (Postfix, from userid 20848) id A9B37B4163; Mon, 10 Nov 2014 12:41:47 -0500 (EST) In-Reply-To: <87zjc2dic0.fsf@gmail.com> (Nicolas Petton's message of "Fri, 07 Nov 2014 18:35:43 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82, MC_TSTLAST 0.00) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 132.204.24.67 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:176698 Archived-At: > +;; Sequence manipulation functions As noticed in the previous review, this just repeats what's already on the first line, so that's not useful. OTOH An important info would be to define what we mean by "sequence" here, more specifically which kinds of sequences are supported. Also we could document here the conventions that we tried to follow. E.g. what is the argument ordering. > +(require 'pcase) Why? The `pcase' macro is autoloaded, so you should only need to (require 'pcase) if you want top use macros like pcase-dolist. > +(defun seq-filter (pred seq) > + "Return a list filtering with PRED all elements of SEQ." Doesn't say if PRED returning nil means "keep" or "throw away". > + (delq nil (mapcar (lambda (elt) > + (and (funcall pred elt) elt)) > + seq))) This will filter out the nil elements, regardless of `pred'. > +(defun seq-reduce (function seq &optional initial-value) > + "Reduce FUNCTION across SEQ, starting with INITIAL-VALUE if not nil." You don't say how FUNCTION will be called. > + (or (listp seq) (setq seq (append seq '()))) > + (let ((acc (or initial-value (if (seq-empty-p seq) > + (funcall function) > + (car seq))))) If you want an initial value of nil but your function can only be called with 2 arguments, you're screwed :-( Would it be a real problem if we simply made `initial-value' an mandatory argument? > +(defun seq-some-p (pred seq) > + "Return any element for which PRED is true in SEQ, nil otherwise." ^^^^ Usually we say "non-nil". > + (catch 'seq-some-p-break Since this tag is internal, I'd use a "seq--" prefix. I think `seq--break' should be sufficient. Of course you could also just use cl-block and cl-return and circumvent the question. > +(defun seq-every-p (pred seq) > + "Return t if (PRED item) is non-nil for all elements of the sequence SEQ." ^ non-nil > +(defun seq-empty-p (seq) > + "Return t if the sequence SEQ is empty, nil otherwise." ^ non-nil > +(defun seq-sort (seq pred) > + "Return a sorted list of the elements of SEQ compared using PRED." I wonder if that's really the more useful behavior, compared to the "inplace" sorting of `sort', or compared to the alternative is always returning a new sequence, but of the same type as the `seq' argument. > +(defun seq-concatenate (type &rest seqs) > + "Concatenate, into a sequence of type TYPE, the argument SEQS. > +\n(fn TYPE SEQUENCE...)" You need to document the values that TYPE can take. Maybe you can simply refer to `type-of'. > +(defalias 'seq-copy #'copy-sequence) > +(defalias 'seq-elt #'elt) > +(defalias 'seq-length #'length) I think mapc would make a lot of sense, and I guess mapcar as well. Not sure if we should name them `seq-mapc' and `seq-mapcar' or something else. > +(load "emacs-lisp/sequences") I think I'd rather not preload it for now and let people use (require 'seq) for that. There's 30 years of accumulated Elisp code and we're not going to switch them to use a new naming scheme overnight. It might even be that people will simply not like to have to add "seq-" in their code (I know they complained about adding "cl-"), so I'd start by simply providing the library and when its popularity grows (and/or is being used by preloaded code) we can then add it to loadup. Stefan