home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / b / binprolog / !BinPro330 / progs / lsort < prev    next >
Encoding:
Text File  |  1994-12-13  |  464 b   |  18 lines

  1. p:-[lsort].
  2.  
  3. % modified version of a Lolli program (sort.ll) by J. Hodas
  4. % I have added \+ hyp and got rid of original explicit continuation passing
  5. % as in BinProlog -<> is already defined in terms of assumel/1
  6.  
  7. collect([]).
  8. collect([X]) :- hyp(X).
  9. collect([X,Y|L]) :- hyp(X), collect([Y|L]), X @=< Y.
  10.  
  11. unpack([]).
  12. unpack([X|L]) :- assumel(hyp(X)), unpack(L).
  13.  
  14. lsort(L,K) :- unpack(L), collect(K), \+ hyp(X).
  15.  
  16. go:-lsort([10,2,33,10,24,2],R),write(R),nl,fail.
  17. go.
  18.