Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!security!genrad!decvax!harpo!floyd!clyde!akgua!psuvax!burdvax!presby!seismo!hao!hplabs!sri-unix!Cohen%UCBKIM@Berkeley From: Cohen%UCBKIM%Berkeley@sri-unix.UUCP Newsgroups: net.lang.prolog Subject: none Message-ID: <14002@sri-arpa.UUCP> Date: Fri, 18-Nov-83 15:26:14 EST Article-I.D.: sri-arpa.14002 Posted: Fri Nov 18 15:26:14 1983 Date-Received: Tue, 29-Nov-83 06:13:09 EST Lines: 121 From: Cohen%UCBKIM@Berkeley (Shimon Cohen) I guess we are all fans of Prolog, are we ? Well, some of us are convinced that Prolog will take over Lisp, ada and the next 1000 languages, Some are curious to see what it is all about, AND some are afraid to be left behind the JAPANese ... I guess we all agree that most languages are equivalent to Turing machine meaning: you can do almost anything in any language, so the qustion is "what makes one language "better" then the other ? " Usually we compare: Efficiency, clarity, readability, features (services provided by the language) mathematical background etc. My experience with Prolog shows that it is not always superior to other languages (for example Lisp) but in certain applications it is !!! So I ask myself ( and all of you out there ) : 1. Are you really convinced that Prolog should replace Lisp, pascal, ada or some of them ? 2. In what areas you feel that Prolog is better and in what it is the same or worse ? 3. Aren't you afraid that Prolog will become another APL type language, good for very specific applications ? I would like to give an Example where Prolog seems to be superior to Lisp and other languages. I wrote the famous Eliza program in Prolog, it seems to be almost 3 times shorter then the Lisp implementation and much more clear, efficient etc. /* Start of program */ top :- repeat,write(' you: '),main,fail. main :- read_sent( Sent ),!, replace_list( Sent, Rsent ),!, /* replace i --> you etc */ key_list( Rsent, Ks ), sort( Ks, Sk ),reverse( Sk, Skeys ),!, try_keys( Skeys, Rsent, Answer ), /* get an answer */ write(' doc: '),print_reply( Answer ), nl. pm( [],[] ). /* pattern matcher in Prolog ... see data file */ pm( [X|L1], [X|L2] ) :- pm(L1,L2),!. pm( [oneof(Options,X) | L1], [X|L2]) :- member(X,Options), pm(L1,L2). pm( [mvar(X) | L], L2) :- append(X,L1,L2), pm(L,L1). replace_list( [], [] ). replace_list( [X|L], [Y|L1] ) :- replace(X,Y),!, replace_list(L,L1). replace_list( [X|L], [X|L1] ) :- !,replace_list(L,L1). key_list( [], [key(-1,none)] ). key_list( [K|L1], [ key(P,K)|L2] ) :- priority(K,P), key_list(L1,L2). key_list( [K|L1], L2 ) :- key_list(L1,L2). try_keys( Keys, Rsent, Outsent ) :- member( key(P,K1), Keys ), /* select a key (generator) */ trule( K1, Ptrn, Nans, Ans ), /* find a rule */ pm( Ptrn, Rsent ),!, /* match ? */ random( Nans, N ), /* get random number upto Nanswers */ get_answer(Ans,N,Outsent). /* get the answer from choices */ get_answer( [A|L], 0, A). get_answer( [B|L], N, A) :- N1 is N - 1, get_answer(L,N1,A). /* end of Eliza main system The following describes the data file for the Eliza (Doctor) program. The data consists the following: 1. Transformations rules that are of the form: trule(Keyword,Pattern,Number_of_answers,Answer_list). where: a. Pattern is the sentence pattern for the keyword. b. Number_of_answers - how many available answers for this keyword+pattern. c. Answer_list - list of available answer for this pattern+keyword. In the patterns: mvar(A) stands for zero or more words. A stands for any one word. oneof(List,A) stand for A is one of the words in List. Note that in some cases a keyword can acquire the transformation rule of another keyword and a certain pattern might include answers of another keyword. 2. Replacement rules in the form: replace(A,B) - replace A by B. 3. Priority rules in the form: priority(A,N) - the priority of keyword A is N. If a keyword does not have a priority rule it is assumed to be of priority 0. The priorities are in ascending order. EXAMPLES: --------- /* Note the way variables from the pattern are used in the answers */ trule(your, [mvar(A),your, oneof([mother,father,brother,sister,husband],C), mvar(B)], 5, [['Tell',me,more,about,your,family,'.'], ['Is',your,family,important,to,you,'?'], ['Who',else,in,your,family,B,'?'], ['Your',C,'?'], ['What',else,comes,to,your,mind,when,you, think,of,your,C,'?']]). . . .. replace(i,you). replace(you,i). replace(computers,computer). . . . priority(computer,40). priority(remember,5). priority(if,3). . . .