-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Improve list comprehensions quicksort example #8008
Conversation
CT Test Results 1 files 11 suites 5m 34s ⏱️ Results for commit d9687b5. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except for a typo.
While you are it, perhaps it would be a good idea to mention that while this way to sort makes a neat example, a more efficient way to sort in Erlang is lists:sort/1
?
@bjorng on a different but related topic... In the example code, there is a list concatenation like At first I thought that this is an inefficient way to do things (simple enough for an example, though), assuming that the first However, timing the two approaches does not yield any difference. The timings vary wildly within each of the approaches, but on average they seem to amount to the roughly same. This makes me suspect that there is some compiler magic at work? |
5fb160f
to
55a1f83
Compare
IIRC the compiler optimizes an expession For strings there is even more special treatment: 0> "a" ++ x = [$a | x].
[97|x] |
Yes, as @RaimoNiskanen said, the list But far more important is that That means that the expression
meaning that each of the lists |
Co-authored-by: Björn Gustavsson <[email protected]>
803c736
to
d9687b5
Compare
Thanks for the explanation @bjorng and @RaimoNiskanen 🤗 |
Hm, I don't see any special treatment for specifically strings here? I mean, |
Thanks for your pull request. |
Actually, I just wanted to add a missing word, but then went on to make the description a little more elaborate and hopefully clearer. The nested list structure may seem a little too much, but I think this way the explanation is more structured.