Skip to content
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

Explain properties of the lt keyword for sorting #41029

Merged
merged 2 commits into from
Jun 2, 2021

Conversation

sostock
Copy link
Contributor

@sostock sostock commented May 31, 2021

The sort! docstring does not explain what kind of properties the function lt needs to have (mainly that it must be irreflexive, like < and unlike ≤). This can lead to confusion (see this discourse thread for example), so it would be good to add a note.

I tried to avoid technical terms like “strict total order”, but maybe the note could be more precise?

@vtjnash vtjnash added the docs This change adds or pertains to documentation label May 31, 2021
base/sort.jl Outdated
Comment on lines 677 to 679
!!! warn
The `lt` function must be a "less than" function (as opposed to a "less than or equal" function),
i.e., for every `x` and `y`, only one of `lt(x,y)` and `lt(y,x)` can return `true`.
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit pedantic to me here, obviously "less than" is not the same as "less than or equal". Perhaps we could mention that "for every x and y, only one of lt(x,y) and lt(y,x) can return true." in the block above though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I have removed the warning block and added the note to the paragraph above.

@simeonschaub simeonschaub merged commit 6be3652 into JuliaLang:master Jun 2, 2021
@simeonschaub
Copy link
Member

Thanks!

shirodkara pushed a commit to shirodkara/julia that referenced this pull request Jun 9, 2021
* Explain restrictions on lt functions

* Remove warn block, add note in text
johanmon pushed a commit to johanmon/julia that referenced this pull request Jul 5, 2021
* Explain restrictions on lt functions

* Remove warn block, add note in text
@ViralBShah ViralBShah added the sorting Put things in order label Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation sorting Put things in order
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants