Skip to content

add: -interleave-any#401

Open
hrehfeld wants to merge 4 commits intomagnars:masterfrom
hrehfeld:interleave-any
Open

add: -interleave-any#401
hrehfeld wants to merge 4 commits intomagnars:masterfrom
hrehfeld:interleave-any

Conversation

@hrehfeld
Copy link
Copy Markdown

@hrehfeld hrehfeld commented Jun 7, 2022

An -interleave that interleaves all elements of all lists.

@hrehfeld
Copy link
Copy Markdown
Author

hrehfeld commented Jun 7, 2022

Doc string of -interleave should mention that it skips elements of longer lists, btw.

@magnars
Copy link
Copy Markdown
Owner

magnars commented Jun 7, 2022

This should be named -interleave-all to match -partition vs -partition-all

@hrehfeld
Copy link
Copy Markdown
Author

hrehfeld commented Jun 7, 2022

You're right, that's much better. Done.

@basil-conto basil-conto self-requested a review June 7, 2022 09:26
Copy link
Copy Markdown
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a welcome addition!

See my comments below for some minor nitpicks mostly related to Emacs/Dash conventions.

My only real request is that you please add some examples/tests for -interleave-all in dev/examples.el. The first three examples listed there will automatically be added to README.md and dash.texi. There is no problem if you are unable or unwilling to regenerate these docs; someone else will do that before/after merging.

BTW, I think this PR is small enough to be exempt from copyright assignment (CA) to the FSF; see (info "(emacs) Copyright Assignment"). However, if it's possible you'll contribute again in the future, I would recommend getting started on the CA process now, so that you're ready to go when the time comes. If you are willing to do this and have not already done so, please fill out and email the following form, and you'll be instructed on how to proceed by the copyright clerk: https://git.sv.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future

Comment thread dash.el Outdated
Comment on lines +1598 to +1600
"Return a new list of the first item in each of `lists', then the
second etc. Continue interleaving all elements of all lists by
skipping the non-existing elements of short lists."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please follow the Emacs docstring conventions outlined in (info "(elisp) Documentation Tips") and implied by this project's dir-locals-file, specifically:

  • The first sentence (summary) of the docstring should fit on a single line.
  • Argument names (metavariables) should be formatted as LISTS rather than as `lists'.
  • Sentences should end with a full stop followed by two spaces.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in -interleave (and other docstrings) as well then.

Copy link
Copy Markdown
Author

@hrehfeld hrehfeld Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted it to "Return a new list containing an element of each of `LISTS' in turn, including all elements. ".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, that doesn't even fit into the insane 70 fill-column. I have no idea how to describe this in a good way that fits into 70 chars. :(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed in -interleave (and other docstrings) as well then.

Of course, and you're more than welcome to include a fix for that as well! ;)

Dash is a large library that historically didn't follow all Emacs conventions, so fixing everything at once is too big a task in practice. Personally whenever I get the time I try to leave whichever parts I touch in a better state than I found them, and I try not to introduce new non-compliant code, even if it's closely related to existing non-compliant code. Eventually, everything will be consistent, or at least that's the hope. :)

Wait, that doesn't even fit into the insane 70 fill-column. I have no idea how to describe this in a good way that fits into 70 chars. :(

The only thing that has to be less than 70-80 characters is the first line, the summary. I know coming up with a useful summary is hard, but once that's achieved the rest of the docstring can elaborate on what the summary is trying to say.

Comment thread dash.el Outdated
Comment thread dash.el Outdated
Comment thread dash.el Outdated
@basil-conto basil-conto added the enhancement Suggestion to improve or extend existing behavior label Jun 7, 2022
@hrehfeld
Copy link
Copy Markdown
Author

hrehfeld commented Jun 9, 2022

Done, incorporated the comments.

@hrehfeld
Copy link
Copy Markdown
Author

Any input on this?

Copy link
Copy Markdown
Collaborator

@basil-conto basil-conto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any input on this?

Sorry to keep you waiting, life got in the way.

Thanks for addressing the feedback! I think the only remaining blocker is the failing CI due to the docstring; see below.

Comment thread dash.el Outdated
(declare (pure t) (side-effect-free t))
(when lists
(let (result)
(while (--some (consp it) lists)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is the same as (--some it lists), right?

Comment thread dash.el Outdated
(nreverse result))))

(defun -interleave-all (&rest lists)
"Return a new list containing an element of each of `LISTS' in turn, including all elements. "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the first version of this docstring was a much clearer description. :) The only problem with it was that the first sentence wasn't a summary that fit entirely on a single line. Apart from clarity, the current version has three technical issues:

  1. As you found out, it is longer than 80 characters, which emits an error during byte-compilation in Emacs 28+ and thus CI fails.
  2. Metavariables are written unquoted, i.e. `LISTS' -> LISTS.
  3. There is spurious trailing whitespace after the full stop.

Suggest writing something like the following instead:

  "Zip all elements from each of LISTS into a new flat list.

That is, return a list comprising the first item from each of
LISTS in turn, followed by their second items, etc.

Continue interleaving until all elements from all LISTS are
included, skipping non-existing elements from shorter LISTS.
This is like `-interleave', but the interleaving continues until
all input elements are consumed, instead of stopping after one of
LISTS becomes empty."

Comment thread dev/examples.el
Comment on lines +1464 to +1465
(-interleave '(1 2) '("a" "b")) => '(1 "a" 2 "b")
(-interleave '(1 2) '("a" "b") '("A" "B")) => '(1 "a" "A" 2 "b" "B")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-interleave -> -interleave-all

@basil-conto basil-conto self-assigned this Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Suggestion to improve or extend existing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants