Subject: setof

From: "Noord G.J.M. van" <[email-masked]>
Date: Tue, 21 Mar 2000 14:15:38 +0100 (MET)

Waseem Besada writes:
 > 
 > Hi,
 > 
 > Why ?-setof(X,course(_,_,X),L). does not give a sorted list L of teachx
 > from the following facts.
 > 
 > course(java,time(monday,10,12),name(teach1)).
 > course(prog, time(friday,13,15), name(teach2)).
 > course(math, time(thrusday,8,10), name(teach3)).
 > course(c,time(wednesday,13,15), name(teach2)).
 > course(prolog, time(friday,10,12), name(teach4)).
 > 

use setof(X,Y^Z^course(Y,Z,X),L).

here, Y^Z^ existenially bind the Y and Z variables.

In  most cases, the following is more efficient, and quite likely
good enough:

findall(X,course(_,_,X),L0), sort(L0,L).

Gj

-- 
Gertjan van Noord Alfa-informatica, RUG,  Postbus 716, 9700 AS Groningen
vannoord at let dot rug dot nl            http://www.let.rug.nl/~vannoord/