I came across this code, which was supposed to demonstrate a Prolog program that couldn't be written in Mercury. I couldn't help but rewrite that as:
rank(Xs,Rs) :- pairs_keys_values(Decorated,Xs,Rs), keysort(Decorated,Sorted), numerate(Sorted,1). numerate(,_). numerate([_-N|Rest],N) :- N1 is N + 1, numerate(Rest,N1).
...This computes the rank order of a list of elements. For example
[3,2,4,1], since 40 is the third largest element, etc.