Maybe it is just me. I think the underlying reason is the generous use of the forward slash in the text. For example, we find the following pairs (with a bit of context, because I am not even sure how should this parse, if we would strictly follow the author’s intention)
library(heaps): heaps/priority queues
a central element of algorithms such as best-first/A* search and Kruskal’s minimum-spanning-tree algorithm
meaning that items are retrieved in ascending order of key/priority
Although the data items can be arbitrary Prolog data, keys/priorities must be ordered by @=</2
This all sounds okey until the predicate definitions, which look like this:
add_to_heap(+Heap0, +Priority, ?Key, -Heap)
Adds Key with priority Priority to Heap0, constructing a new heap in Heap.
Here is an attempt to demonstrate that the Priority from the definition above is used; but the Key is not. I used X and Y in the queries so that I don’t have to name it something confusing. The docs claim:
min_of_heap(+Heap, ?Priority, ?Key)
Unifies Key with the minimum-priority element of Heap and Priority with its priority value. Complexity: constant.
?- empty_heap(_H0),
add_to_heap(_H0, 1, foo, _H1),
add_to_heap(_H1, 1, bar, _H2),
min_of_heap(_H2, X, Y).
X = 1,
Y = bar.
?- empty_heap(_H0),
add_to_heap(_H0, 1, bar, _H1), % same elements
add_to_heap(_H1, 1, foo, _H2), % but inserted in different order
min_of_heap(_H2, X, Y).
X = 1,
Y = foo.
This is also easily seen in the source code.
The use of “key/priority” in the docs, together with the naming of the arguments, is in my opinion inconsistent. I suspect the original author meant to use “key/priority” when documenting the second argument from the definition of add_to_heap/4 above, and use “data item” for the third argument.
Am I tripping? Is this a bit confused or is it me? I can make a PR if it turns out that other are also confused.
PS: the docs are confusing at first but the library itself is quite useful!