unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Alex Branham <alex.branham@gmail.com>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
	33309@debbugs.gnu.org, Stefan Monnier <monnier@IRO.UMontreal.CA>
Subject: bug#33309: Add flatten-list?
Date: Tue, 11 Dec 2018 09:21:14 +0100	[thread overview]
Message-ID: <87a7lccw3p.fsf@gmx.de> (raw)
In-Reply-To: <87pnu9m0ou.fsf@gmail.com> (Alex Branham's message of "Mon, 10 Dec 2018 17:17:21 -0600")

Alex Branham <alex.branham@gmail.com> writes:

Hi Alex,

> Yes, that does seem better, updated patch attached. I also updated the
> docstring to explicitly state how it handles nil values and dotted
> pairs.

The docstring doesn't say what happens if TREE isn't a list. Something like

(flatten-tree 42) => (42)

I'm wondering also, whether we shall make removing nil elements optional:

(defun flatten-tree (tree &optional omit-nil)
...

Or, if we expect that removing nil elements shall be default:

(defun flatten-tree (tree &optional keep-nil)
...

>  lisp/eshell/em-basic.el  |  2 +-
>  lisp/eshell/em-dirs.el   |  4 ++--
>  lisp/eshell/em-term.el   |  2 +-
>  lisp/eshell/em-tramp.el  |  4 ++--
>  lisp/eshell/em-unix.el   | 22 +++++++++++-----------
>  lisp/eshell/em-xtra.el   |  2 +-
>  lisp/eshell/esh-ext.el   |  2 +-
>  lisp/eshell/esh-opt.el   |  4 ++--
>  lisp/eshell/esh-util.el  | 12 ++----------
>  lisp/gnus/gnus-sum.el    | 10 +++++-----
>  lisp/gnus/message.el     | 12 ++----------
>  lisp/gnus/nnimap.el      |  2 +-
>  lisp/lpr.el              | 20 ++------------------
>  lisp/net/tramp-compat.el | 13 +------------
>  lisp/printing.el         |  2 +-
>  lisp/progmodes/js.el     |  8 ++------
>  lisp/subr.el             | 20 ++++++++++++++++++++
>  test/lisp/subr-tests.el  | 13 +++++++++++++

I suppose we need also an entry in etc/NEWS and doc/lispref/lists.texi.

> diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el
> index 046966e019..4f99a31e54 100644
> --- a/lisp/net/tramp-compat.el
> +++ b/lisp/net/tramp-compat.el
> @@ -270,18 +270,7 @@ tramp-compat-use-url-tramp-p
>  	    (unload-feature 'tramp-loaddefs 'force)
>  	    (unload-feature 'tramp-compat 'force)))
>  
> -;; There does not exist a common `flatten-list' yet, this is discussed
> -;; in Bug#33309.  For the time being we implement our own version,
> -;; derived from `eshell-flatten-list'.
> -(defun tramp-compat-flatten-list (args)
> -  "Flatten any lists within ARGS, so that there are no sublists."
> -  (let ((new-list (list t)))
> -    (dolist (a args)
> -      (if (and (listp a)
> -	       (listp (cdr a)))
> -	  (nconc new-list (tramp-compat-flatten-list a))
> -	(nconc new-list (list a))))
> -    (cdr new-list)))
> +(define-obsolete-function-alias 'tramp-compat-flatten-list #'flatten-tree "27.1")
>  
>  (provide 'tramp-compat)

Please don't do this. Tramp must support Emacs back to version 24. Once
flatten-tree has hit the git repository, I'll modify tramp-compat.el accordingly.

> --- a/test/lisp/subr-tests.el
> +++ b/test/lisp/subr-tests.el
> @@ -372,5 +372,18 @@ subr-test--frames-1
>                              (shell-quote-argument "%ca%")))
>                     "without-caret %ca%"))))
>  
> +(ert-deftest subr-tests-flatten-tree ()
> +  "Test `flatten-tree' behavior."
> +  (should (equal (flatten-tree '(1 (2 . 3) nil (4 5 (6)) 7))
> +                 '(1 2 3 4 5 6 7)))
> +  (should (equal (flatten-tree '((1 . 2)))
> +                 '(1 2)))
> +  (should (equal (flatten-tree '(1 nil 2))
> +                 '(1 2)))
> +  (should (equal (flatten-tree 42)
> +                 '(42)))
> +  (should (equal (flatten-tree '(1 ("foo" "bar") 2))
> +                 '(1 "foo" "bar" 2))))
> +
>  (provide 'subr-tests)
>  ;;; subr-tests.el ends here

I would also add

(should (equal (flatten-tree t)
               '(t)))
(should (equal (flatten-tree nil)
               nil))

> Alex

Best regards, Michael.





  parent reply	other threads:[~2018-12-11  8:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a7lccw3p.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=33309@debbugs.gnu.org \
    --cc=alex.branham@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).