Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornell!travelers.mail.cornell.edu!news.kei.com!news.mathworks.com!uunet!usc!howland.reston.ans.net!ix.netcom.com!netcom.com!brahme
From: brahme@netcom.com (brahme)
Subject: Sofar(X, predicate(X), SOfarlist, X) wanted in prolog
Message-ID: <brahmeD4Ixrv.M9o@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
Date: Fri, 24 Feb 1995 21:45:31 GMT
Lines: 49
Sender: brahme@netcom17.netcom.com

Hi: 

About a year and half there was a discussion on variants of setof

setof finds all solutions and returns them in a sorted form.
this is of no use when the number of solutions is very large

Another variation for this is sofar(Var, predicate(Var), Sofarlist, Curvar)
This works the first time it is called it returns

 After call
    1       sofar(Var, predicate(Sol1), [], Sol1)
After backtracking on second call it returns
    2       sofar(Var, predicate(Sol2), [Sol1], Sol2).
After another failure when it is called again it returns
    3      sofar(Var, predicate(Sol3), [Sol1, Sol2], Sol3)

In short this is predicate that collects the history of solutions with the boundary condition being
setof which collects the final history

Now again this is of limited use if the history is large, one can go one step furthur and have 
    
   n_sofar(N, Var, predicate(Sol), Nlist, Sol)

where say for N = 2 it will save only a history of 2 solutions

  n_sofar(2, Var, predicate(Sol1), [], Sol1) 

on backtracking would generate
 
 n_sofar(2, Var, predicate(Sol2), [Sol1], Sol2),

on 2nd backtracking would generate

 n_sofar(2, Var, predicate(Sol3), [Sol1, Sol2], Sol3)

and on third backtracking will generate

 n_sofar(2, Var, predicate(Sol4), [Sol2, Sol3], Sol4).


Is any prolog vendor providing this. Any one willing to generate a builtin optimal version of this

This should'nt be difficult for the prolog implementor since they already produce setof and this nothing

but a simplified version of setof.


Dhan Brahme
