unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#33309: Add flatten-list?
@ 2018-11-07 19:46 Alex Branham
  2018-11-07 20:36 ` Drew Adams
  2018-12-11 17:36 ` bug#33309: [PATCH] flatten-list Alex Branham
  0 siblings, 2 replies; 19+ messages in thread
From: Alex Branham @ 2018-11-07 19:46 UTC (permalink / raw)
  To: 33309

[-- Attachment #1: Type: text/plain, Size: 1038 bytes --]

Could we add a new function `flatten-list'? There seems to be a need for
it. Inside Emacs itself, I see at least four implementations of the same
basic thing:

- eshell-flatten-list
- message-flatten-list
- lpr-flatten-list
- js--flatten-list

And there are many more in the various 3rd-party packages.

I was thinking of putting it in subr.el. What do you think?

Thanks,
Alex

diff --git a/lisp/subr.el b/lisp/subr.el
index 41dc9aa45f..3ea75ddf56 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5447,5 +5447,14 @@ This function is called from lisp/Makefile and leim/Makefile."
     (setq file (concat (substring file 1 2) ":" (substring file 2))))
   file)

+(defun flatten-list (list)
+  "Take LIST and \"flatten\" it.
+The result will be a list containing all the elements of LIST.
+\(flatten-list \\='(1 (2 3 (4 5 (6))) 7))
+=> (1 2 3 4 5 6 7)"
+  (cond ((null list) nil)
+        ((consp list) (append (flatten-list (car list))
+	                      (flatten-list (cdr list))))
+        (t (list list))))

 ;;; subr.el ends here

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

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

end of thread, other threads:[~2018-12-17 11:33 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-07 19:46 bug#33309: Add flatten-list? Alex Branham
2018-11-07 20:36 ` Drew Adams
2018-11-07 21:19   ` Alex Branham
2018-12-10  8:44     ` Michael Albinus
2018-12-10 17:49       ` Stefan Monnier
2018-12-10 20:12         ` Alex Branham
2018-12-10 21:36           ` Stefan Monnier
2018-12-10 23:06             ` Alex Branham
2018-12-11 12:36               ` Stefan Monnier
2018-12-10 22:42           ` Basil L. Contovounesios
2018-12-10 23:17             ` Alex Branham
2018-12-10 23:26               ` Basil L. Contovounesios
2018-12-10 23:34               ` Stephen Berman
2018-12-11  8:21               ` Michael Albinus
2018-12-11  8:34               ` martin rudalics
2018-12-11 17:36 ` bug#33309: [PATCH] flatten-list Alex Branham
2018-12-11 20:11   ` Michael Albinus
2018-12-11 20:16     ` Alex Branham
2018-12-17 11:33       ` Michael Albinus

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).