From ok@atlas.otago.ac.nz Fri May  4 03:04:05 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f44143320367
	for <prolog@swi.psy.uva.nl>; Fri, 4 May 2001 03:04:04 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id NAA212362;
	Fri, 4 May 2001 13:03:54 +1200 (NZST)
Date: Fri, 4 May 2001 13:03:54 +1200 (NZST)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200105040103.NAA212362@atlas.otago.ac.nz>
To: jpar@aegean.gr, prolog@swi.psy.uva.nl
Subject: Re:  [SWIPL] sorting database?

Partsakoulakis Ioannis <jpar@aegean.gr> 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).

