Skip to content

Documentation and spec fixes in lists, queue, sets, ordsets and gb_sets#10844

Open
juhlig wants to merge 1 commit intoerlang:masterfrom
juhlig:stdlib_docs_fixes_1
Open

Documentation and spec fixes in lists, queue, sets, ordsets and gb_sets#10844
juhlig wants to merge 1 commit intoerlang:masterfrom
juhlig:stdlib_docs_fixes_1

Conversation

@juhlig
Copy link
Contributor

@juhlig juhlig commented Mar 13, 2026

This PR contains a number of non-code fixes for the lists, queue, sets, ordsets and gb_sets modules. See exemplary inline comments.

  * gb_sets
  * lists
  * ordsets
  * queue
  * sets
@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

CT Test Results

    2 files     99 suites   1h 9m 42s ⏱️
2 283 tests 2 232 ✅ 51 💤 0 ❌
2 700 runs  2 644 ✅ 56 💤 0 ❌

Results for commit cc9b295.

♻️ 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


```erlang
1> S0 = gb_sets:from_ordset(lists:seq(1, 100)).
1> S0 = gb_sets:from_list(lists:seq(1, 100)).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While the usage of from_ordset is not wrong here, it may be confusing to readers. Everybody knows from_list and can intuitively guess at what it does. OTOH, the usage of from_ordset assumes that the reader knows the assumption that the given list is sorted and free of duplicates.

Comment on lines +850 to +852
Returns an iterator over members of `Set` in the given `Order`, starting
from `Element` or, if absent, the first member that follows in the
iteration order, if any; see `next/1`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is easier to read, and that the references to iterator/1,2 are not needed. Also, the passage saying "... the first element greater than or equal to..." in the original text was only correct for the ordered case, while in the reversed case it actually is "... the first element less than or equal to...".

Comment on lines -1103 to +1085
SetList :: [set(Element),...],
SetList :: [set(Element)],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

union([]) is allowed and results in an empty set, so the argument list may be empty.

Comment on lines -1224 to +1206
This function is equivalent to `gb_sets:intersection(Set1, Set2) =:= []`,
This function is equivalent to `gb_sets:is_empty(gb_sets:intersection(Set1, Set2))`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gb_sets:intersection will return a gb_set, not an empty list, so the comparison with [] will always be false even if the two sets are disjoint.

Comment on lines -1496 to +1478
gb_sets:from_list(lists:filtermap(Fun, Set1)).
gb_sets:from_list(lists:filtermap(Fun, gb_sets:to_list(Set1))).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assuming that Set1 is a gb_set, lists:filtermap(Fun, Set1) would not work here.

-spec nthtail(N, List) -> Tail when
N :: non_neg_integer(),
List :: [T,...],
List :: [T],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nthtail(0, []) works and returns [], so empty lists are actually allowed.

```
""".
-spec new() -> [].
-spec new() -> ordset(none()).
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overlooked?


This function is equivalent to `ordsets:intersection(Ordset1, Ordset2)
=:= []`, but faster.
This function is equivalent to `ordsets:is_empty(ordsets:intersection(Ordset1, Ordset2))`, but faster.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While not wrong and the representation backing ordsets is not opaque, I think using lists and ordsets ambiguosly should not be encouraged, but rather the usage of the respective API functions.

Comment on lines -577 to +576
Fun :: fun((Element1 :: T1) -> boolean | ({true, Element2 :: T2})),
Fun :: fun((Element1 :: T1) -> boolean() | {true, Element2 :: T2}),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

boolean (atom) instead of boolean() (type)

Comment on lines -730 to +735
4> Queue1 = queue:filtermap(fun (E) -> {true, E+100} end, Queue).
{"ihg","ef"}
5> queue:to_list(Queue1).
"efghi
4> Queue2 = queue:filtermap(fun (E) -> {true, E - 100} end, Queue).
{[-95,-96,-97],[-99,-98]}
5> queue:to_list(Queue2).
[-99,-98,-97,-96,-95]
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 result of the filtermap and subsequent to_list calls ended up prettified to "strings", which might be confusing to readers.

- `from_list/1`
- `intersection/1`
- `intersection/2`
- `is_disjoint/2`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All set implementations export this function, with same semantics (sans matching vs comparing equal, as usual).

@bjorng bjorng self-assigned this Mar 14, 2026
@bjorng bjorng added the team:VM Assigned to OTP team VM label Mar 14, 2026
@bjorng bjorng changed the title Documentation and spec fixes in lists, queue, sets, ordests and gb_sets Documentation and spec fixes in lists, queue, sets, ordsets and gb_sets Mar 18, 2026
Copy link
Contributor

@bjorng bjorng left a comment

Choose a reason for hiding this comment

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

Thanks for your pull request.

@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants