Skip to content

fix example comment in Enum.slide/3 #13779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged

Conversation

davidsulc
Copy link
Contributor

No description provided.

@@ -2706,11 +2706,11 @@ defmodule Enum do
iex> Enum.slide([:a, :b, :c, :d, :e, :f, :g], 5, 1)
[:a, :f, :b, :c, :d, :e, :g]

# Slide a range of elements backward
Copy link
Member

Choose a reason for hiding this comment

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

Both interpretations can be right, but semantically, it is forward, because we are bringing the elements from 3..5 to position 1 (and as a result, the ones from 1..2 are brought forward, but the ones we specify go back).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the ones we specify go back

Could you expand on that a little? Which elements are "the ones we specify" and what do you mean by "go back"?

I'd interpret the elements we specify as the 3..5 slice, i.e. elements [:d, :e, :f]. Originally, these elements are in positions 3-5, but after the slide/3 call, they are in positions 1-3. As these elements have moved towards the head of the list, wouldn't this be "going forward"?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see where the confusion is coming from, it is about what is forward, the head or the tail? What if instead of forwards and backwards and we say "towards the head" and "towards the tail"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was indeed the source of my confusion: "forward" being "in the reading direction" vs "toward the list head". I've reworded the change to remove ambiguity. Thanks for clarifying your meaning!

@josevalim josevalim closed this Aug 14, 2024
@josevalim josevalim reopened this Aug 14, 2024
"forward" could mean

- towards the head of the list
- farther in the reading direction (i.e., farther to the right)

By referring instead to the list's head/tail, the ambiguity is resolved.
@josevalim josevalim merged commit cf49f8b into elixir-lang:main Aug 14, 2024
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants