Subject: Re: [SWIPL] sorting database?

From: "Richard A. O'Keefe" <[email-masked]>
Date: Fri, 4 May 2001 13:03:54 +1200 (NZST)

Partsakoulakis Ioannis <[email-masked]> wrote:
that he wants to keep the facts in a predicate in ascending order.

	Is this possible?
	
No.  Consider
    on(1, 1).
    on(1, 3).
...
    assert(( on(X, Y) :- X = 1, Y = 2 )).

If that's not sufficiently convincing, try

    assert(( on(1, Y) :- member(Y, [2,4]) ))

which would have to be in two places at the same time.

	If not how can I retrieve efficiently the fact on(X,Y) such that
	Ys are returned in increasing order?
	
In general, relying on the order in which solutions are returned is
unwise.  Occasionally it is extremely unwise.  You may need to do

    on_increasing(X, Y) :-
	setof(Y, on(X,Y), Ys),
	member(Y, Ys).