[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#33309: Add flatten-list?
From: |
Basil L. Contovounesios |
Subject: |
bug#33309: Add flatten-list? |
Date: |
Mon, 10 Dec 2018 23:26:56 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Alex Branham <alex.branham@gmail.com> writes:
> Basil, if you want git author credit, feel free to use yourself as the
> author since you wrote the function :-)
No need, thanks. :)
> diff --git a/lisp/subr.el b/lisp/subr.el
> index d3bc007293..52ac475cc6 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -5448,5 +5448,25 @@ unmsys--file-name
> (setq file (concat (substring file 1 2) ":" (substring file 2))))
> file)
>
> +(defun flatten-tree (tree)
> + "Take TREE and \"flatten\" it.
> +This always returns a list containing all the elements of TREE.
> +Dotted pairs are flattened as well, and nil elements are removed.
> +
> +\(flatten-tree \\='(1 (2 . 3) nil (4 5 (6)) 7))
> +=> (1 2 3 4 5 6 7)"
> + (let (elems)
> + (setq tree (list tree))
> + (while (let ((elem (pop tree)))
> + (cond ((consp elem)
> + (setq tree (cons (car elem) (cons (cdr elem) tree))))
> + (elem
> + (push elem elems)))
> + tree))
Is it just me, or is the indentation a bit off here?
Thanks,
--
Basil
- bug#33309: Add flatten-list?, Michael Albinus, 2018/12/10
- bug#33309: Add flatten-list?, Stefan Monnier, 2018/12/10
- bug#33309: Add flatten-list?, Basil L. Contovounesios, 2018/12/10
- bug#33309: Add flatten-list?, Alex Branham, 2018/12/10
- bug#33309: Add flatten-list?,
Basil L. Contovounesios <=
- bug#33309: Add flatten-list?, Stephen Berman, 2018/12/10
- bug#33309: Add flatten-list?, Michael Albinus, 2018/12/11
- bug#33309: Add flatten-list?, martin rudalics, 2018/12/11