SWI-Prolog -- order_by/2

Did you know ... Search Documentation:
SWI-Prolog owl logo Predicate order_by/2
Availability::- use_module(library(solution_sequences)).(can be autoloaded)
Source order_by(+Spec, :Goal)
Order solutions according to Spec. Spec is a list of terms, where each element is one of. The ordering of solutions of Goal that only differ in variables that are not shared with Spec is not changed.
asc(Term)
Order solution according to ascending Term
desc(Term)
Order solution according to descending Term

This predicate is based on findall/3 and (thus) variables in answers are copied.

Tags are associated to your profile if you are logged in|Report abuse
Tags:
  • doc-needs-help
Stuart Reynolds said (2020年09月21日T23:20:30):0 upvotes 0 0 downvotes
Picture of user Stuart Reynolds.

Found it very hard to grok without an example. Here is one: =https://swish.swi-prolog.org/p/order_by%20example.swinb=[Your text to link here...](https://swish.swi-prolog.org/p/order_by%20example.swinb)

data(0, 1, 1).
data(1, 0, 0).
data(0, 0, 0).
data(1, 2, 0).
data(1, 0, 1).
data(0, 2, -1).
data(1, 1, 1).
data(0, 1, 0).
?- order_by([desc(B),asc(C)], data(A,B,C)).
A = 0, B = 2, C = -1 ;
...

For more see: Your text to link here...

login to add a new annotation post.

AltStyle によって変換されたページ (->オリジナル) /