bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#33309: Add flatten-list?


From: Alex Branham
Subject: bug#33309: Add flatten-list?
Date: Wed, 07 Nov 2018 13:46:29 -0600
User-agent: mu4e 1.1.0; emacs 27.0.50

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: signature.asc
Description: PGP signature


reply via email to

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