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