home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / programm / 3382 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  1.8 KB

  1. Path: sparky!uunet!pipex!bnr.co.uk!uknet!mucs!m1!bevan
  2. From: bevan@cs.man.ac.uk (Stephen J Bevan)
  3. Newsgroups: comp.programming
  4. Subject: Re: Programming by Description of Output...
  5. Message-ID: <BEVAN.92Dec31202001@panda.cs.man.ac.uk>
  6. Date: 31 Dec 92 20:20:01 GMT
  7. References: <1992Dec30.174004.4168@cs.cornell.edu> <C036t1.KCH@phage.cshl.org>
  8.     <BEVAN.92Dec31001940@panda.cs.man.ac.uk>
  9.     <1992Dec31.155736.29068@cs.cornell.edu>
  10. Sender: news@cs.man.ac.uk
  11. Organization: Department of Computer Science, University of Manchester
  12. Lines: 28
  13. In-reply-to: karr@cs.cornell.edu's message of 31 Dec 92 15:57:36 GMT
  14.  
  15. In article <1992Dec31.155736.29068@cs.cornell.edu> karr@cs.cornell.edu (David Karr) writes:
  16.    >  sort(List, Sorted_List) :-
  17.    >    permutation(List, Sorted_List),
  18.    >    ordered(Sorted_List).
  19.  
  20.    My impression is that most of the work of writing this specification
  21.    is in the spec of "permutation", a smaller amount is in "ordered", and
  22.    the part shown above is trivial in comparison.  So the above example
  23.    doesn't make much of an impression on me.
  24.  
  25. I don't think the whole spec. makes much of an impression either, what
  26. does is an example of the transformation from the spec. to a program.
  27. Since I don't have any of the work I mentioned to hand I can't give an
  28. example of that.  As a consolation, here are some spur of the moment
  29. (i.e. not guaranteed to be correct) definitions of "permutation" and
  30. "ordered" :- 
  31.  
  32.  permutation(A,B) :- length(A,L), length(B,L), range(A,X), range(B,Y), eq(X,Y).
  33.  ordered([]).
  34.  ordered([H|T]) :- item_ordered(H,T), ordered(T).
  35.  item_ordered(_,[]).
  36.  item_ordered(A,[H|T]) :- less_than_or_equal_to(A,H), item_ordered(A,T).
  37.  
  38. "range" returns the elements of a list as a set and "eq" compares sets
  39. for equality.  Note Prolog doesn't have "set" as a native type, so
  40. there is a level of detail hidden there.
  41.  
  42. bevan
  43.