For Programmers: Free Programming Magazines  


Home > Archive > Prolog > August 2005 > TESS for Turbo Prolog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author TESS for Turbo Prolog
chuen

2005-08-03, 5:03 pm

TESS for Turbo Prolog
This is " The Expert System Shell "of program.
That is run for Turbo prolog.
Can you tell me that will run into Visual Prolog

% File : Main-Mod.pro

% The Main Modules of the expert system shell.

code = 2750.
trail = 300.
config "prolog.sys"
include "c:\\example\\tess\\glb-mod.pro" % domains and database
declarations
include "c:\\example\\tess\\ut-mod.pro" % utility module
include "stcl-mod.pro" % string to clausal form interpreter
include "tr-mod.rpo" % include translation predicates
include "wind-mod.pro" % windows module, also calls "menu-mod.pro"
include "io-mod.pro" % input/output utility predicates
include "user-mod.pro" % inference engine, know_how & know_why
include "ask-mod.pro" % The consultation module

predicates
nondeterm run.
nondeterm choice(INTEGER).
nondeterm stop(INTEGER).
goal
run.

clauses % To run the shell program the goal must be: "run"
run :- repeat, % at ut-mod.pro
main_window, % at wind-mod.pro
main_menu(CHOICE), % at wind-mod.pro
choice(CHOICE),
stop(CHOICE), !.

"stop"
A backtrackable predicate to cause failure if choice between 1 and 8
so that
"repeat" will brings back to main menu. and options are allowed to de
selected
again.
stop(0). % If ESC is pressed

stop(9):- % Exit the system
write("Are you sure? (y or n) "),
readchar(C), write(C), C='y',
goodby_window,
write("\n The \n End"),
wait_count(2000), % at ut-mod.pro
removewindow, % remove goodbye window
removewindow, % remove frame window
exit.

% Branching from the main menu window to other windows

choice(1):- % Load a knowledge base
load_know, !. % "load_know" is in file "io-mod.pro"

% Getting one or more Conjuncted or Disjuncted Goals.
choice(2):- % Consultation Mode
consult_window,
get_goal(GoalStr), % Get the string that represnt a goal
interpret(GoalStr,Goal_Relations_List), % in Tr-mod.pro
answer_goals(Goal_Relations_List,_), % in User-mod.pro
removewindow,
!.
% Answering one goal only

choice(2) :- % Consultation Mode
consult_window,
get_goal(GoalStr), % Get the string that represents a goal
str_rel(GoalStr,Goal,""),
s_call([],Goal,[],Out,0),
write(out),
removewindow,
!.

/* When the first choice(2) predicats fails, the second one prints the
reason of that there are no
knowledge base in memory and then remove the window. Thus the last
"choice" predicate which is
"choice(_)" will not fire. The last "choice(_)" predicate is used to
move the option window if the
"choice" option fails and we need to remove its window before going
back to the main menu. */
choice(2) :-
write("\n\n\n Sory , I am unable to answer you query."),
write("\n For some details on that enter ? at the prompt > "),
readln(R), R = "?",
write("\n find an answer to you query. \n"),
write("\n I suggest you either had no knowledge being loaded"),
write("\n in the system or you need to eidt the KB file you"),
write("\n already loaded, erase the knowledge base, and then"),
write("\n load this KB file once more and go into the "),
write("\n consultation mode to ask your query once more."),
readln(_), % removewindow,
!.

choice(2). % Go back to main menu any way

choice(3):- % Edit Knowledge Base
edit_window,
edit_know, % "edit_know" in file "io-mod.pro"
removewindow,
!.

choice(4):- % Listing the memory resident knowledge base
list_window, list_know,
removewindow,
!.

choice(5):- % Erase Knowledge Base
erase, !. % "erase" is in file "ut-mod.pro"

choice(6):- % Save Knowledge Base
add_confirmed_facts, % in "io-mod.pro"
save_knowA, !. % "save_know" is in file "io-mod.pro"

choice(7):- % Print Knowledge Base
print_know, !. % print_output is in "io-mod.pro"

choice(8):- system(""), !. % Dos shell

choice(9):- !. % Exit the system by using "stop" predicate */
% Cut here is important to allow proper and */
choice(_). %:- removewindow. % program - 1

chuen

2005-08-05, 5:02 pm



% File: glb-mod.pro

% The global domains, predicates and declarations module
% This module is called by "main-mod.pro"
GLOBAL DOMAINS
INT = reference INTEGER
INTEGERLIST = INYTEGER*
REALlist = REAL*
LSTRINGlist = STRIMGLIST*
data_fileA, PARAMETER = reference SYMBOL
PARIR = pair(PARAMETER, PARAMETER, INT)
PAIRlist = PAIR*
PARMlist = PARAMETER*
Llist = PARMlist* % Llist is s list of list
Hlist = Llist* % history list is a list of lists of lists
Plist = PAIRlist* % pair list is a list of of lists of pairs
CL = cl(PARMlist, Llist) % "cl" stands for clauses
CLlist = CL*
FILE = kba_file infile
% Domains used for the menu-mod.pro
STRINGlist = STRING*
KEY = cr; esc; break; tab; btab; del; bdel; ins; end; home;
ftast(INTEGER);
up; down; left; right; tegn(CHAR); otherspec

DATABASE
cl(PARMLlist, Llist)
data_file(STRING)
history(Llist)
confirmed(PARMlist)
topic(PARAMETER)
% program-2


Question ?
Can you tell me in comp.lang.prolog?
How many version of prolog. i.e turbo prolog, visual prolog
Swi prolog ... and ???

Thanks

student

2005-08-06, 9:02 am

chuen wrote:

>
> % File: glb-mod.pro
>
> % The global domains, predicates and declarations module
> % This module is called by "main-mod.pro"


What about all the other include files, like

include "c:\\example\\tess\\ut-mod.pro" % utility module
include "stcl-mod.pro" % string to clausal form interpreter
include "tr-mod.rpo" % include translation predicates
include "wind-mod.pro" % windows module, also calls "menu-mod.pro"
include "io-mod.pro" % input/output utility predicates
include "user-mod.pro" % inference engine, know_how & know_why
include "ask-mod.pro" % The consultation module

?

I don't know anything about TESS but if you will email me a zip file
containing the complete source code (not just bits and pieces of it), I
will be happy to invest a few hours of my time trying to make it run on
Visual Prolog 5.2.
--
Bill
logic4sure@yahoo.com
chuen

2005-08-07, 4:01 am

% File: UT-Mod.pro

% The Utility predicates module.

% To run this module you need this include statement:
include "glb-mod.pro"
goal
makewindow(1,7,7,"Test window",5,5,15,70),
write("\nPress any key to remove the window"),
readchar(_),
removewindow().
predicates
erase. % Erase all facts in the knoeledge base
% Special Consulting predicate
my_consult(STRING)
strint(PARMlist,INTEGERlist)
strreal(PARMlist,REALlist)
repeat
repeat_file(file)

member(PAIR,PAIRlist)
member(PARAMETER,PARMlist)
member(PARMlist,lList)
unique_member(PAIR,PAIRlist)
n_mamber(INTEGER,PARAMAETER,PARMlist)
append(lList,lList,lList)
append(PARMlist,PARMlist,PARMlist)
no_dup(PARMlist,PARMlist)
nomore(PARAMETER,PARMlist,PARMlist)
reverse_list(lList,lList)
rev(lList,lList,lList)
% String processing utility
variable(PARAMETER) /* This check if a string stands for variable */
capital(STRING) /* this checks if letter is a capital letter */
scr_disp(PAEAMETER,INT)
scr_dispA(PARAMETER,INT,INT)
concat_list(PARAMlist,PARAMETER)
concat_str_list(PARMlist,PARAMETER,PARAM
ETER)
% Special effects predicates
wait_count(INT) % Do the waiting by a number counting loop
tone(INT,INT,INT) % Play a tone
highlight(STRING,INT) % The numInt is for the color of text
write_list(PARMlist)
% Predicates for text-graphics
box1(INTEGER,INTEGER,INTEGER,INTEGER)
graphic_set1(STRING,STRING,STRING,STRING
,STRING,STRING)
% uses "box"
box2(INTEGER,INTEGER,INTEGER,INTEGER)
graphic_set2(STRING,STRING,STRING,STRING
,STRING,STRING)
% uses "box"

box(INTEGER,INTEGER,INTEGER,INTEGER,STRI
NG,STRING,STRING,STRING,STRING,STRING)
repeatSTRING(INTEGER,STRING,STRING)
write_vertical(INTEGER,INTEGER,INTEGER,S
TRING)
ascii_str(INTEGER,STRING)
CLAUSES % Utility predicates
member(X,[X|_]):- !.
member(X,[_|Y]):- member(X,Y).

unique_member(pair(_,_,_),[]).
unique(pair(X,Y,N),[pair(A,B,N)|T)) :- bound(X), bound(Y),
X<>A,
Y<>B,
unique_member(pair(X,Y,N),T).
% Extracting the n'th member of the list
n_member(1,X[X|_]).
n_member(N,X,[_|Y]):- n_member(M,X,Y), N = M + 1.

append([],X,X).
append([X|L1],L2,[X|L3]):- append(L1,L2,L3).
% Get a list with no duplicates
no_dup([],[]).
no_dup([H|T],[H|Rest]):- nomore(H,T,NewT), no_dup(NewT, Rest).

nomore(_, [], []).
nomore(H,[H|T],R):- nomore(H,T,R), !.
nomore(H,[X|T],[X|R]):- nomore(H,T,R).
% Reverseing a list sould be in Ut-mod.Pro
reverse_list(L1,L2):- rev(L1,[],L2).
rev([X|L1],L2,L3):- rev(L1,[X|L2],L3).
rev([],L,L).
% Consulting a file
my_consult(FileName):- openread(kba_file, FileName),
readdevice(kba_file),
repeat_file(kba_file),
readterm(Dbasedom, Term),
assertZ(Term), fail.
my_consult(_):- eof(kba_file).
/* ************************************* */

repeat.
repeat :- repeat.

repeat_file(_).
repeat_file(File):- not(eof(File)),
repeat_file(File).
% Special effects
% Wait until the count number is over
wait_count(0).
wait_count(Number):- New_Number = Nember - 1, wait_count(New_Number).
% Play a tone
tone(0,_,_).
tone(Repeats,Duration,Frequency):- R = Repeats - 1,
D = Duration + 1,
F = Frequency + 1,
sound(Duration, Frequency), tone(R, D, F).
% Highlighting a string of characters in a certain color
highlight(String, Color):-
str_len(String, Length),
cursor(Row, Col),
write(String),
field_attr(Row, Col, Length, Color).
% Display the contents of a list on one line
write_list([]).
write_list([LastName]):- write(LastName, ".").
write_list([BeforeLast, Last]):- write(BeforeLast, " and "),
write_list([Last]).
write_list([H|T]):- write(H, ", "), write_list(T).
% ------
strint([],[]).
strint([HS|TS],[HI|TI]):-
bound(HS),
str_int(HS,HI),
strint(TS,TI).

strreal([],[]).
strreal([HS|TS],[HR|TR]):-
bound(HS),
str_real(HS,HR),
strreal(TS,TR).
% Erase asserted facts ------
erase:- retract(_), fail.
erase.
% check if a letter is a capital letter ------
variable(X):- frontstr(1,X,CHAR,_), capital(CHAR).

capital(X):- upper_lower(X,Y), Y<>X.

% concatenate a list of strings into one string ------
concat_list(StrList,OutStr):-
concat_str_list(StrList," ",OutStr).

concat_str_list([],InStr,InStr):- !.
concat_str_list({HString|TString],InStr,
OutStr):-
concat(InStr,HString,Str),
concat_str_list(TString,Str,OutStr).

% Screen display 2 ------
/* This predicate is use in the explanation mode to control the
number of lines to be displayed in a window. This will allow the
user to read the contents of a window before the text moves up. */
scr_disp(String,MaxNum):- scr_dispA(String,0,MaxNum).

scr_dispA("",_,_):- write("\n\n Hit any key to end display"),
readln(_), clearwindow, !.
scr_dispA(String,Num,Num):- write("\n\n Hit any key to go to next
screen"),
readln(_), clearnwindow, sr_dispA(String,0,Num), !.
scr_dispA(String,Num,MaxNum):- frontchar(String,'\n',Rest),
write("\n"), NewNum = Num +1, scr_dispA(Rest,NewNum,MaxNum), !.
scr_dsipA(String,Num,MaxNum):- frontchar(String,'\t',Rest),
write("\t"), scr_dispA(Rest,Num,MaxNum), !.
scr_dispA(String,Num,MaxNum):- fronttoken(String,H,Rest),
write(" ",H), scr_dispA(Rest,Num,MaxNum).

% Text Graphics ------

% Drawing a box in a text window
/* A box has a starting point with (ROW,COL) coordinates. The box
dimensions are specified by LENGTH of the box to the left of
starting point, The WIDTH of the box is down from the starting
point.
(ROW,COL)
+---------> LENGTH
|
|
WIDTH */

box1(ROW,COL,LENGTH,WIDTH):- graphic_set1(UL,UR,LL,LR,H,V),
box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
).

box2(ROW,COL,LENGTH,WIDTH):- graphic_set2(UL,UR,LL,LR,H,V),
box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
).

box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
):-
Hlength = LENGTH - 1,
Vwidth - WIDTH - 1,
Row1 = Row + WIDTH, % Row for lower line of the box
Col1 = Col + LENGTH, % Col For right line of the box
Row2 = Row + 1,
Col2 = Co1 + 1,
Cursor(ROW,COL),
repeatSTRING(Hlength,H,HstrA),
concat(UL,HstrA,HstrB),
concat(HstrB,UR,HstrU),
write(HstrU), % upper horizontal line with corners
cursor(Row1,Col),
concat(LL,HstrA,HstrC),
concat(HstrC,LR,HstrL),
write(HstrL), % Lower horizontal line with corners
write_vertical(Row2,Col,Vwidth,V), % left vertical line
write_vertical(Row2,Col1,Vwidth,V). %rigth vertical line

% Graphic Characters sets ------

graphic_set1(ULcorner,URcorner,LLcorner,
LRcorner,Horz,Vert):-
ascii_str(201,ULcorner), % upper left corner
ascii_str(200,LLcorner), % lower left corner
ascii_str(187,URcorner), % upper right corner
ascii_str(188,LRcorner), % lower right corner
ascii_str(205,Horz), % horizontal line segment
ascii_str(186,Vert). % vertical line segment

graphic_set2(ULcorner,URcorner,LLcorner,
LRcorner,Horz,Vert):-
ascii_str(213,ULcorner), % upper left corner
ascii_str(212,LLcorner), % lower left corner
ascii_str(184,URcorner), % upper right corner
ascii_str(190,LRcorner), % lower right corner
ascii_str(205,Horz), % horizontal line segment
ascii_str(179,Vert). % vertical line segment

% concatenate a string-part a number of times ------

repeatSTRING(0,_,"").
repeatSTRING(Number.PartString,String):-
LessNUmber = Number - 1,
repeatSTRING(LessNumber,PartString,OldSt
ring),
concat(PartString,OldString,String).

% Draw a vertical line of a certain ASCII character

write_vertical(_,_,0,_).
write_vertical(Row,Col,Hight,STRcode):-
cursor(Row,Col),
write(STRcode),
Row1 = Row + 1,
Hight1 = Hight - 1,
write_vertical(Row1,Col,Hight1,STRcode).

% ASCII decimal to string translation ------
/* Translate a decimal number representing an ASCII character
to the string equivalent of that number. */

ascii_str(ASCIIcode,STRcode):-
char_int(CHARcode,ASCIIcode),
str_char(STRcode,CHARcode).

% program-3

chuen

2005-08-07, 4:01 am

% File: stcl-mod.pro

/* In this module the predicate "readFile(FileName)" reads the
file "FileName" and translates facts and rules written in the
standard Turbo Prolog form, i.e.

likes(safaa,philosophy).
likes(safaa,Person):-
likes(Safaa,Hobby),
likes(Person,Hobby).
And it converts this form into database clasue facts:

cl([likes,safaa,philosophy],[]).
cl([likes,safaa,"Person"],[[likes,safaa,"Hobby"],
[likes,safaa,"Hobby"]]).

after it does that it asserts them to the knowledge base.
Note: The commented subgoals if asserts them to added will allow the
saving
of the knowledge base to a ".cls" file */

/* To run the program by itself you need these inclusion/s:
include "glb-mod.pro" */

predicates
readFILE(STRING).
analyseFILEname(STRING,STRING,STRING)
repeat % in ut-mod.pro
getCLAUSE(PARAMETER,PARAMETER).
checkPERIOD(PARAMETER).
str_cls(PARAMETER,PARAMETER).
str_cl(PARAMETER,PARAMETER).
str_rel(PARAMETER,PARMlist,PARAMETER).
get_string_parm(PARAMETER,PARAMETER,PARA
METER).
str_body(PARAMETER,Llist,PARAMETER).
clauses
% readFILE ------
readFILE(InFILEname):-
analyseFILEname,NAme,_),
readdevice(infile),
repeat,
getCLAUSE("",CLAUSE),
str_cls(CLAUSE,""),
eof(infile),
readdevice(keyboard).
concat(NAme,".cls",SaveFileName),
save(SaveFileName).
analyseFilename(STRname,Name,Extension):
-
fronttoken(STRname,Name,Rest),
fronttoken(Rest,".",Extension).

% get CLAUSE ------
getCLAUSE(Line,""):-
checkPERIOD(Line), !.
getCLAUSE(_,Block):-
readln(Line),
getCLAUSE(Line,PartBlock),
concat(Line,"\n",Str),
concat(Str,PartBlock,Block).
checkPERIOD(""):- !, fail.
checkPERIOD(Line):-
fronttoken(Line,".",_), !.
checkPERIOD(Line):-
fronttoken(Line,_,RestLine),
checkPERIOD(RestLine).

% Translating from strings into clauses ------

/* This a new version of Str_cls which asserts clauses directly
in the knowledge base without building a list of clauses.
we use this to save space */

str_cls("","").
str_cls(Text,Rest):- % ignore a new line char
frontchar(Text,'\n',RestA),
str_cls(RestA,Rest), !. % translate the char
str_cls(Text,Rest):- % ignore space char
frontchar(Text,' ',RestA),
str_cls(RestA,Rest), !.
str_cls(Text,Rest):-
str_cl(Text,RestA), % reanslate one clause at a time
str_cls(RestA,Rest), !. % go back and translate the rest
str_cls(_,_):-
write("\n failing to convert a string into database clauses."),
fail.
str_cl(Text,Rest):- % if the clause is a fact
str_rel(Text,Hrel,RestA),
fronttoken(RestA,".",Rest),
assertz(cl(Hrel,[])), !.
str_cl(Text,Rest):- % the clause is a rule
str_rel(Text,Hrel,RestA),
str_body(RestA,Trels,Rest),
assertz(cl(Hrel,Trels)).

/* when encountring ")" we signals the end of the relation
for example a relation:
likes(safaa,reading) is translated into [Likes,safaa,reading]
| | |
ignore ignore end */

str_rel("",[],""):- !.
str_rel(Text,[],Rest):-
fronttoken(Text,")",Rest), !.
% and ignore "(" or ","

str_rel(Text,Parms,Rest):-
fronttoken(Text,"(",RestA),
str_rel(RestA,Parms,Rest), !.
str_rel(Text,Parms,Rest):-
fronttoken(Text,",",RestA),
str_rel(RestA,Parms,Rest), !.
str_rel(Text,[Hparm|Tparm],Rest):- % get quoted string as parm
fronttoken(Text,"\"",RestA),
get_string_parm(RestA,Hparm,RestB),
str_rel(RestB,Tparm,Rest), !.
str_rel(Text,[Hparm|Tparms],Rest):-
fronttoken(Text,Hparm,RestA),
str_rel(RestA,Tparms,Rest), !.
str_rel(Text,Parms,Rest):-
frontchar(Text,'\n',RestA),
str_rel(RestA,Parms,Rest).

% get_string_parm ------
/* "get_string_parm" takes a string that had started with a quote
sign (") and collects the words from the begining of the string
till another (") is detected. When closing quote (") is detected
the string between the quotes is returned. */

get_string_parm(Str,"",RestStr):-
fronttoken(Str,"\"",RestStr), !.
get_String_parm(Str,Parm,RestStr):-
frontchar(Str,' ',RestA),
get_string_parm(RestA,RestParm,RestStr),

concat(" ",RestParm,Parm), !.
get_string_Parm(Str,Parm,RestStr):-
fronttoken(Str,Token,RestA),
get_string_parm(RestA,RestParm,RestStr),

concat(Token,RestParm,Parm).

% Str_body ------
/* capturing the body of a rule (condotioned clause) */
str_body(Text,[],Rest):- % "." signals end of rule
fronttoken(Text,".",Rest), !.
str_body(Text,Relations,Rest):- % ignore "if"
fronttoken(Text,"if",RestA),
str_body(RestA,Relations,Rest), !.
str_body(Text,Relations,Rest):- % ignore ":-"
fronttoken(Text,":",RestA),
fronttoken(RestA,"-",RestB),
str_body(RestB,Relations,Rest), !.
str_body(Text,Relations,Rest):- % ignore ","
fronttoken(Text,",",RestA),
str_body(RestA,Relations,Rest), !.
str_body(Text,Relations,Rest):- % ignore "and"
fronttoken(Text,"and",RestA),
str_body(RestA,Relations,Rest), !.
str_body(Text,[Hrel|Trel],Rest):- % collect list of relations
str_rel(Text,Hrel,RestA),
str_body(RestA,Trel,Rest).

/* repeat.
repeat :- repeat. */
% program-4

------------------------------------------------------
Please wait, Because I will typing it, that need to a less of time.
Thanks

student

2005-08-07, 5:02 pm

chuen wrote:

> Please wait, Because I will typing it, that need to a less of time.
> Thanks
>


I see.

_@ (you are typing in lots of mistakes, so please take as much time
as you need because I have to find them and correct them :)
chuen

2005-08-08, 5:03 pm

% File: tr-mod.pro program-5

% The translation module of the expert system shell.

/* This module facilitates the translation between strings and clausal
form. Predicate relations are lists. Facts and rules are expressed
using the database fact "cl(Head,Body)" where Head is a predicate
relation represented as a list of string. The body is a list of
predicate relations each is itself a list of strings.

Note: so for in this form of representation no lists are allowed as
parameters in facts or rules. This module is called by the main
module "main-mod.pro".
- - - - - -
Explaining the main predicates in this module"
The predicate: "cl_str(Head,Body,String)" has the flow
pattern (i,i,o). It takes the head and body of a clause
and gives a string equivalent of it. For example the clause:
cl([credit_is,Name,good],[[debt_is,Name,
0],
[min_savings,Name,3000]]).
would be translated to its string equivalent form:
credit_is(Name,good):-
debt_is(Name,0),
min_savings(Name,3000).
The "cl_str" predicate is used to rewrite the difficult to
read clausal form in a better form.
- - - - - -
The predicate: " str_cls(String,HeadAndBody,RestOfString)
"

On the other hand we also need to allow the user to enter his
facts and rules in a less restrictive form, sucj as the one
used in entering the Turbo Prolog programs using the editor.
To do that we need a translation predicate from the string
form to the clausal form. For this purpose we provided the
"cls_str" and "cl_str" predicates.

"str_cls" is used a "readFILE" to do the reading of a file
assumed top be in a string form. It then asserts the facts
rules to the database when it finds them. readFILE is
designed to read a file line by line because of the
limitation on the string size Turbo Prolog can handel
in the program. So "readfile" reduces demand on memory.

STRING to CLAUSAL FORM translation is given in the file
"stcl-mod.pro" */

/* To run this module by itself you need just to:
include "glb-mod.pro"

include "glb-mod.pro"
and/or
include "stcl-mod.pro"
*/
predicates
% translating from clauses to strings
nondeterm cl_str(PARMlist,Llist,PARAMETER).
nondeterm body_str(List,PARAMETER).
nondeterm rel_str(PARMlist,PARAMETER).
nondeterm rel_str_A(PARMlist,PARAMETER,PARAMETER).
nondeterm relations_str(Llist),PARAMETER).
nondeterm relations_strA(List,PARAMETER,PARAMETER)
.
% uses "rel_str"
% Translating a string representing a goal into a list of relations
nondeterm interpret(PARAMETER,Hlist).
nondeterm interpret1(PARAMETER,Llist,PARAMETER).
nondeterm write_cl_list(CLlist).
nondeterm transform(CLlist,PARAMETER).

clauses
% translating clauses into strings
% interpreting clauses into factual sentences
cl_str(Relation,[],Sentence):-
rel_str(Relation,S1),
concat("\n Fact: ",S1,S2),
concat(S2,".\n",Sentence), !.
% interpreting clauses into instrumental sentences
cl_str(Relation,[HB|TB],Sentence):-
rel_str(Relation,S1),
concat(S1," IF",S2),
body_str([HB|TB],S3),
concat(S2,S3,S4),
concat("\n Rule: ",S4,S5),
concat(S5,".\n",Sentence).
% interpreting the subgoals (conditions) of a rule
body_str([Last],Sentence):-
rel_str(Last,S1),
concat("\n\t ",S1,Sentence), !.
body_str([H|T],Sentence):-
body_str(T,S4),
rel_str(H,S1),
concat("\n\t ",S1,S2),
concat(S2," AND",S3),
concat(S3,S4,Sentence).

% translating a list of parameters into a string
rel_str(["!"],"!"):- !. % CUT
rel_str(["not",RelName|Rest],Sentence):- % NEGATION
rel_str_A(Rest,"",S3),
concat("not(",RelName,S1),
concat(S1,"(",S2),
concat(S2,S3,S4),
concat(S4,")",Sentence), !.
rel_str([RelName|Rest],Sentence):-
rel_str_A(Rest,"",S2),
concat(RelName,"(",S1),
concat(S1,S2,Sentence), !.
rel_str_A([H],InStr,Sentence):-
concat(Instr,H,S1),
concat(S1,")",Sentence), !.
rel_str_A([H|T],InStr,Sentence):-
bound(H),
concat(InStr,H,S1),
concat(S1,",",S2),
rea_str_A(T,S2,Sentence).

% Translating a string representing a goal ------
/* When a goal can be:
(a) a single question that can be translated into a list of alist of
single relation:
IS john likes mary --> likes(john,mary) --> [[[Likes,john,mary]]]
IS X likes Y --> likes(X,Y) --> [[[likes,"X","Y"]]]
(answer by true or false)
WHICH X likes Y --> likes(X,Y) --> [[[likes,"X","Y"]]]
(Get one or more answers, instantiate variables X and Y)
ALL X likes Y --> likes(X,Y) --> [[[likes,"X","Y"]]]
(Get all answers, instantiate X and Y to all possible values)
(b) a conjunction of subgoals (questions connected by AND or ","):
IS GOAL1 and GOAL2 --> GOAL1,GOAL2 --> [[GOAL1,GOAL2]]
where GOAL1 and GOAL2 can be a relation as "{likes,tom,bill]."
same for WHICH
same for ALL
(c) a disjunction of subgoals (questions connected by OR or ";"):
IS GOAL1 or GOAL2 --> GOAL1,GOAL2 --> [[GOAL1],[GOAL2]]
(d) a disjunction and conjunction of sub-goals:
IS GOAL1 and GOAL2 or GOAL3 and GOAL4 or GOAL5
GOAL1, GOAL2; GOAL3, GOAL4; GOAL5.
[[GOAL1,GOAL2],[GOAL3,GOAL4],[GOAL5]]

To establish the list of goal relations in this case we start
from the left and open a first list of conjuncted subgoals, For
each "AND" or "and" or "," we append another relation to the
first sublist. If we encounter "OR" or "or" ";" we end the
first sublist and open a second sublist. This continues untill
no more tokens exist in the string of the goal. */

interpret("",[]).
interpret(GoalStr,[SubGoals|Tail]):-
interpret1(GoalStr,SubGoals,Rest),
interpret(Rest,Tail), !.
interpret1("",[],_):- !.
interpret1(GoalStr,[],RestStr):-
fronttoken(GoalSstr,"or",RestStr);
fronttoken(GoalStr,"OR",RestStr);
fronttoken(GoalStr,";",RestStr), !.
interpret1(GoalStr,GoalRels,Rest):-
fronttoken(GoalStr,",",RestStr),
interpret1(RestStr,GoalRels,Rest), !.
interpret1(GoalStr,GoalRels,Rest):-
fronttoken(GoalStr,"and",RestStr),
interpret1(RestStr,GoalRels,Rest), !.
interpret1(GoalStr,GoalRels,Rest):-
fronttoken(GoalStr,"AND",RestStr),
interpret1(RestStr,GoalRels,Rest), !.
interpret1(GoalStr,[Relation|RestRel],Re
stStr):-
str_rel(GoalStr,Relation,Rest),
interpret1(Rest,RestRel,RestStr).

% Transform a list of "cl" facts into a string ------
transform([],"").
transform([cl(H,B)|T],Str):-
cl_str(H,B,Str1),
transform(T,Str2),
concat(Str1,Str2,Str).

% translating a list of relations into a string, in tr-mod.pro
relations_str(RelList,OutStr):-
relations_StrA(RelList,"",OutStr).
relations_StrA([],InStr,InStr):- !.
relations_StrA([H|T],InStr,OutStr):-
rel_Str(H,Str1),
concat("\n\n\t",Str1,Str2),
concat(InStr,Str2,Str3),
relations_StrA(T,Str3,OutStr).

% A write predicates to write "cl" facts
write_cl_list([]).
write_cl_list([H|T]):- write("\n\t",H), write_cl_list(T).
% program-5

--------------------------------------------------------------------
O'yes.
Thanks

chuen

2005-08-08, 5:03 pm

% File: UT-Mod.pro program-3

% The Utility predicates module.

% To run this module you need this include statement:
include "c:\\example\\tess\\glb-mod.pro"
predicates
nondeterm erase. % Erase all facts in the knoeledge base
% Special Consulting predicate
nondeterm my_consult(STRING).
nondeterm strint(PARMlist,INTEGERlist).
nondeterm strreal(PARMlist,REALlist).
nondeterm repeat.
nondeterm repeat_file(file).

nondeterm member(PAIR,PAIRlist).
nondeterm member(PARAMETER,PARMlist).
nondeterm member(PARMlist,lList).
nondeterm unique_member(PAIR,PAIRlist).
nondeterm n_mamber(INTEGER,PARAMAETER,PARMlist).
nondeterm append(lList,lList,lList).
nondeterm append(PARMlist,PARMlist,PARMlist).
nondeterm no_dup(PARMlist,PARMlist).
nondeterm nomore(PARAMETER,PARMlist,PARMlist).
nondeterm reverse_list(lList,lList).
nondeterm rev(lList,lList,lList).
% String processing utility
nondeterm variable(PARAMETER). % This check if a string stands for
variable
nondeterm capital(STRING). % this checks if letter is a capital
letter
nondeterm scr_disp(PAEAMETER,INT).
nondeterm scr_dispA(PARAMETER,INT,INT).
nondeterm concat_list(PARAMlist,PARAMETER).
nondeterm concat_str_list(PARMlist,PARAMETER,PARAM
ETER).
% Special effects predicates
nondeterm wait_count(INT). % Do the waiting by a number counting loop
nondeterm tone(INT,INT,INT). % Play a tone
nondeterm highlight(STRING,INT). % The numInt is for the color of text
nondeterm write_list(PARMlist).
% Predicates for text-graphics
nondeterm box1(INTEGER,INTEGER,INTEGER,INTEGER).
nondeterm graphic_set1(STRING,STRING,STRING,STRING
,STRING,STRING).
% uses "box"
nondeterm box2(INTEGER,INTEGER,INTEGER,INTEGER).
nondeterm graphic_set2(STRING,STRING,STRING,STRING
,STRING,STRING).
% uses "box"
nondeterm
box(INTEGER,INTEGER,INTEGER,INTEGER,STRI
NG,STRING,STRING,STRING,STRING,STRING).
nondeterm repeatSTRING(INTEGER,STRING,STRING).
nondeterm write_vertical(INTEGER,INTEGER,INTEGER,S
TRING).
nondeterm ascii_str(INTEGER,STRING).

goal
makewindow(1,7,7,"Test window",5,5,15,70),
write("\nPress any key to remove the window"),
readchar(_),
removewindow().

CLAUSES
% Utility predicates
member(X,[X|_]):- !.
member(X,[_|Y]):- member(X,Y).

unique_member(pair(_,_,_),[]).
unique(pair(X,Y,N),[pair(A,B,N)|T)) :- bound(X), bound(Y),
X<>A,
Y<>B,
unique_member(pair(X,Y,N),T).
% Extracting the n'th member of the list
n_member(1,X[X|_]).
n_member(N,X,[_|Y]):- n_member(M,X,Y), N = M + 1.

append([],X,X).
append([X|L1],L2,[X|L3]):- append(L1,L2,L3).
% Get a list with no duplicates
no_dup([],[]).
no_dup([H|T],[H|Rest]):- nomore(H,T,NewT), no_dup(NewT, Rest).

nomore(_, [], []).
nomore(H,[H|T],R):- nomore(H,T,R), !.
nomore(H,[X|T],[X|R]):- nomore(H,T,R).
% Reverseing a list sould be in Ut-mod.Pro
reverse_list(L1,L2):- rev(L1,[],L2).
rev([X|L1],L2,L3):- rev(L1,[X|L2],L3).
rev([],L,L).
% Consulting a file
my_consult(FileName):- openread(kba_file, FileName),
readdevice(kba_file),
repeat_file(kba_file),
readterm(Dbasedom, Term),
assertZ(Term), fail.
my_consult(_):- eof(kba_file).
/* ************************************* */

repeat.
repeat :- repeat.

repeat_file(_).
repeat_file(File):- not(eof(File)),
repeat_file(File).

% Special effects
% Wait until the count number is over
wait_count(0).
wait_count(Number):- New_Number = Nember - 1, wait_count(New_Number).

% Play a tone
tone(0,_,_).
tone(Repeats,Duration,Frequency):- R = Repeats - 1,
D = Duration + 1,
F = Frequency + 1,
sound(Duration, Frequency), tone(R, D, F).

% Highlighting a string of characters in a certain color
highlight(String, Color):-
str_len(String, Length),
cursor(Row, Col),
write(String),
field_attr(Row, Col, Length, Color).

% Display the contents of a list on one line
write_list([]).
write_list([LastName]):- write(LastName, ".").
write_list([BeforeLast, Last]):- write(BeforeLast, " and "),
write_list([Last]).
write_list([H|T]):- write(H, ", "), write_list(T).
% ------
strint([],[]).
strint([HS|TS],[HI|TI]):-
bound(HS),
str_int(HS,HI),
strint(TS,TI).

strreal([],[]).
strreal([HS|TS],[HR|TR]):-
bound(HS),
str_real(HS,HR),
strreal(TS,TR).

% Erase asserted facts ------
erase:- retract(_), fail.
erase.

% check if a letter is a capital letter ------
variable(X):- frontstr(1,X,CHAR,_), capital(CHAR).

capital(X):- upper_lower(X,Y), Y<>X.

% concatenate a list of strings into one string ------
concat_list(StrList,OutStr):-
concat_str_list(StrList," ",OutStr).

concat_str_list([],InStr,InStr):- !.
concat_str_list({HString|TString],InStr,
OutStr):-
concat(InStr,HString,Str),
concat_str_list(TString,Str,OutStr).

% Screen display 2 ------
/* This predicate is use in the explanation mode to control the
number of lines to be displayed in a window. This will allow the
user to read the contents of a window before the text moves up. */
scr_disp(String,MaxNum):- scr_dispA(String,0,MaxNum).

scr_dispA("",_,_):- write("\n\n Hit any key to end display"),
readln(_), clearwindow, !.
scr_dispA(String,Num,Num):- write("\n\n Hit any key to go to next
screen"),
readln(_), clearnwindow, sr_dispA(String,0,Num), !.
scr_dispA(String,Num,MaxNum):- frontchar(String,'\n',Rest),
write("\n"), NewNum = Num +1, scr_dispA(Rest,NewNum,MaxNum), !.
scr_dsipA(String,Num,MaxNum):- frontchar(String,'\t',Rest),
write("\t"), scr_dispA(Rest,Num,MaxNum), !.
scr_dispA(String,Num,MaxNum):- fronttoken(String,H,Rest),
write(" ",H), scr_dispA(Rest,Num,MaxNum).

% Text Graphics ------

% Drawing a box in a text window
/* A box has a starting point with (ROW,COL) coordinates. The box
dimensions are specified by LENGTH of the box to the left of
starting point, The WIDTH of the box is down from the starting
point.
(ROW,COL)
+---------> LENGTH
|
|
WIDTH */

box1(ROW,COL,LENGTH,WIDTH):- graphic_set1(UL,UR,LL,LR,H,V),
box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
).

box2(ROW,COL,LENGTH,WIDTH):- graphic_set2(UL,UR,LL,LR,H,V),
box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
).

box(ROW,COL,LENGTH,WIDTH,UL,UR,LL,LR,H,V
):-
Hlength = LENGTH - 1,
Vwidth - WIDTH - 1,
Row1 = Row + WIDTH, % Row for lower line of the box
Col1 = Col + LENGTH, % Col For right line of the box
Row2 = Row + 1,
Col2 = Co1 + 1,
Cursor(ROW,COL),
repeatSTRING(Hlength,H,HstrA),
concat(UL,HstrA,HstrB),
concat(HstrB,UR,HstrU),
write(HstrU), % upper horizontal line with corners
cursor(Row1,Col),
concat(LL,HstrA,HstrC),
concat(HstrC,LR,HstrL),
write(HstrL), % Lower horizontal line with corners
write_vertical(Row2,Col,Vwidth,V), % left vertical line
write_vertical(Row2,Col1,Vwidth,V). %rigth vertical line

% Graphic Characters sets ------

graphic_set1(ULcorner,URcorner,LLcorner,
LRcorner,Horz,Vert):-
ascii_str(201,ULcorner), % upper left corner
ascii_str(200,LLcorner), % lower left corner
ascii_str(187,URcorner), % upper right corner
ascii_str(188,LRcorner), % lower right corner
ascii_str(205,Horz), % horizontal line segment
ascii_str(186,Vert). % vertical line segment

graphic_set2(ULcorner,URcorner,LLcorner,
LRcorner,Horz,Vert):-
ascii_str(213,ULcorner), % upper left corner
ascii_str(212,LLcorner), % lower left corner
ascii_str(184,URcorner), % upper right corner
ascii_str(190,LRcorner), % lower right corner
ascii_str(205,Horz), % horizontal line segment
ascii_str(179,Vert). % vertical line segment

% concatenate a string-part a number of times ------

repeatSTRING(0,_,"").
repeatSTRING(Number.PartString,String):-
LessNUmber = Number - 1,
repeatSTRING(LessNumber,PartString,OldSt
ring),
concat(PartString,OldString,String).

% Draw a vertical line of a certain ASCII character

write_vertical(_,_,0,_).
write_vertical(Row,Col,Hight,STRcode):-
cursor(Row,Col),
write(STRcode),
Row1 = Row + 1,
Hight1 = Hight - 1,
write_vertical(Row1,Col,Hight1,STRcode).

% ASCII decimal to string translation ------
/* Translate a decimal number representing an ASCII character
to the string equivalent of that number. */

ascii_str(ASCIIcode,STRcode):-
char_int(CHARcode,ASCIIcode),
str_char(STRcode,CHARcode).

% program-3

--------------------------------------------------------------------------
Is this a file, that is error?

student

2005-08-08, 10:02 pm

chuen wrote:
> % File: UT-Mod.pro program-3
>


I will not be able to help you
if you do not tell me where
these programs are coming from.

Are they printed in a book?
If so, what book?



chuen

2005-08-09, 4:02 am

% File : wind-mod.pro program-6

% The Windows Definition Module, called by file "main-mod.pro" */

include "menu.pro" % This file comes with your Turbo Prolog system.

predicates
nondeterm main_window.
nondeterm consult_window.
nondeterm edit_window.
nondeterm save_window.
nondeterm directory_window.
nondeterm list_window.
nondeterm goodby_window.
nondeterm title_window.
nondeterm explaning_why_window.
nondeterm explaning_how_window.
nondeterm info_window.
nondeterm load_window.

nondeterm main_menu(integer).
nondeterm why_menu(integer).
nondeterm how_menu(integer).
nondeterm yesNo_menu(integer).
nondeterm support_menu.
nondeterm topic_menu(parmlist,integer).
nondeterm fileForm_menu(integer).

clauses
% Colors blank screen with "Red on Cyan" frame
main_window:- makewindow(1,7,1,"[Expert System Shell]",0,0,24,80).
% Colors are "cyan on black" and the frame is "white on red"
consult_window:- make(2,79,121,"[Quary The Expert]",1,1,22,78).
% Colors are "green on blank" and frame is "blue on yellow"
edit_window:- makewindow(3,2,105,"[Edit Knowledge]"1,1,22,78).
% Colors are "green on gray", frame is "blue on gray"
save_window:- makewindow(4,10,9,"[File saved will have a (.cls)
extension]",12,1,4,78).
% Colors are "brown on blue", frame is "brown"
directory_window:- makewindow(5,4,6,"[Pick a Knowlege-Base Date
File]",14,3,6,74).
% Colors are "black on white", frame is "red"
list_window:- makewindow(7,112,4,"[Listing the
Knowledge-Base]",4,1,16,78).
% Colors are red on black with brown frame
goodby_window:- makewindow(8,117,6,"",8,35,7,7).
explaning_why_window:- makewindow(9,112,2,"[Know - Why]",1,1,22,78).
explaning_how_window:- makewindow(10,116,4,"[Know - How]",1,1,22,78).
title_window:- makewindow(11,2,4,"[Expert System Shell]",0,0,24,80).
info_window:- makewindow(12,3,6,"[Information Window]",5,2,15,76).
load_window:- makewindow(13,23,6,"[Loading (.cls) or (.str)
file]",9,2,13,76).
main_menu(CHOICE):- menu(1,27,2,6,"< main Menu >",
["Load Knowledge Base ",
"Consultation Mode ",
"Edit Knowledge Base ",
"List Knowledge Base ",
"Erase KnowLedge Base ",
"Save Knowledge Base ",
"Print KnowLedge Base ",
"Dos shell ",
"Exit. "],CHOICE).
support_menu:- menu(4,16,7,113,"[Menu # 2]",
["Consult ",
"Edit ",
"Update ",
"Explain ",
"Dos shell ",
"Save Changes ",
"Exit "],_).
why_menu(CHOICE):- menu(2,65,3,71,"[Inquire]",
["Yes .....",
"No ......",
"Why......"],CHOICE).
how_menu(CHOICE):- menu(2,60,79,121,"[Know How]",
["O.K. ........",
"How........."],CHOICE).
yesno_menu(CHOICE):- menu(2,65,6,2,"[Yes/No]",
["Yes .....",
"No ....."],CHOICE).
topic_menu(List,CHOICE):- menu(2,60,71,3,"[Select a
topic]",List,CHOICE).
fileform_menu(CHOICE):- menu(10,58,4,6,"[File Form]",["Clausal form
..=2E.",
"String Form
..=2E."],CHOICE).
% program-6
---------------------------------------------------------------------------=
------------------
The book is TURBO PROLOG =E9=AB=98=E7=AD=89=E7=A8=8B=E5=BC=8F=E8=
A8=AD=E8=
=A8=88 =E6=A0=BC=E8=87=B4=E5=87=BA=E7=89=88=E7=
A4=BE
I 'm sorry, Thanks

chuen

2005-08-09, 4:02 am

% File : io-mod.pro program-7

% Input and Output utility predicates module.

% to test "list_know" you need to include "tr-mod.pro" also
include "c:\example\\tess\\glb-mod.pro".
include "c:\\example\\tess\\wind-mod.pro".
include "c:\\example\\tess\\ut-mod.pro".
include "c:\\example\\tess\\stcl-mod.pro".
include "c:\\example\\tess\\tr-mod.pro".

predicates
nondeterm edit_know.
nondeterm getEDITfile(STRING).
nondeterm getFILEtype(INTEGER,STRING).
nondeterm save_know(CHAR,STRING,STRING).
nondeterm save_knowA.
nondeterm load_know.
nondeterm pick_file(STRING,STRING).
nondeterm load_knowA(INTEGER).
nondeterm load_know_cl(STRING). % load file in clause form
nondeterm load_know_str(STRING).% load file in string form
nondeterm readFILE(STRING). % at stcl-mod.pro
nondeterm list_know.
nondeterm disp_know_str(List,Hlist,PARAMETER).
nondeterm disp_know_strA(List,Hlist,PARAMETER,PARA
METER).
nondeterm print_know.
nondeterm write_know.
% also uses disp_know_str
nondeterm add_confirmed_facts.
nondeterm erase_confirmed_clauses(Llist).
nondeterm confirmed_facts_str(PARAMETER).

clauses
% Knowledge and file manipulation predicates
% Edit Knowledge-base ------
edit_know :-
getEDITfile(FileName),
file_str(FileName,KBA),
editmsg(KBA,EditedKBA,"Expert System Shell Editor",
FileName,"To exit the editor press ESC or F10.",
1,"help.TXT",_),
clearwindow,
write("Save changes to knowledge base file (enter y or n) "),
readchar(YesNoANs),
save_know(YesNoAns,EditedKBA,FileName).
save_know('y',KBA,Filename) :- openwrite(kba_file,Filename),
writedevice(Kba_file),
write(KBA),
closefile(kba_file).
save_know('n',_,_).
getEDITfile(FileName) :- load_window, %at wind-mod.pro
fileForm_menu(Choice), % in wind-mod.pro
getFILEtype(Choice,FileName),
removewindow.
getFILEtype(1,FileName) :- pick_file("*.cls",FileName).
getFILEtype(2,FileName) :- pick_file("*.str",FileName).

% Save Knowledge-base ------
save_knowA :- cl([date_file,FileName],[]),
% When knowledge was loaded every thing was converted to "cl" form
bound(FileName), !,
save(FileName),
clearwindow,
write("your % Knowledge base has been saved", FileName).
save_knowA :-
save_window,
write(" Enter Knowledge-Base File Name (without extension)."),
write("\n File Name: "),
readln(FileName),
assert(data_file(FileName)),
removewindow,
concat(FileName,".cls",Name),
save(Name),
clearwindow,
writef(" Your % Knowledge base has been saved",Name).

/* convert the asserted "confirmed(Relation)" into facts of the
form "cl(Relation,[])" and assert those to the knowledge base
and retract all confirmed facts. */
add_confirmed_facts:-
findall(Fact,confirmed(Fact),ConfirmedFa
ctsList),
erase_confirmed_facts,
add_confirmed_clauses(ConfirmedFactsList
).

erase_confirmed_facts:-
retract(confirmed(_)), fail.
erase_confirmed_facts.

add_confirmed_clauses([]).
add_confirmed_clauses([H|T]):-
asserta(cl(H,[])),
add_confirmed_clauses(T).

confirmed_facts_str(Str):-
findall(Fact,confirmed(Fact),Fact2),
relations_str(Fact2,Str).

% Load Knowledge-base File ------
load_know:-
load_window, % in wind-mod.pro
fileForm_menu(Choice), % in wind-mod.pro
load_knowA(Choice),
removewindow.

% First: if the file is in "cl" form then load the "cl" facts
load_knowA(1):-
pick_file("*.cls",Name),
load_know_str(Name), !.

% Second: if file is in string form then pick the file to load
load_knowA(2):-
pick_file("*.str",Name),
load_know_str(Name), !.

% Load knowledge in clause form ------
load_know_cl(FileName):-
consult(FileName),
write("\n File ",FileName," is loaded."), !.

% Load knowledge in STRING form ------
load_know_str(FileName):-
readFILE(FileName),
write("\n File ",FileName," is loaded."), !.

% Listing the knowledge-base ------
list_know:-
confirmed_facts_str(Str1),
Str1<>"",
findall(Read,cl(Head,_),Hlist),
findall(Body,cl(_,Body),Blist),
disp_know_str(Hlist,Blist,Str3),
concat_list(["\n The list of confirmed facts are:",Str1,
"\n\n While the original knowledge base is:\n",
Str3],Str),
display(Str), !.
list_know:-
findall(Read,cl(Head,_),Hlist),
findall(Body,cl(_,Body),Blist),
disp_know_str(Hlist,Blist,Str1),
concat(["The knowledge base Have the clause/s:\n",Str1,Str),
display(Str), !.

% disp_know_str ------
disp_know_str(Hlist,Blist,OutStr):-
disp_know_strA(Hlist,Blist,"",OutStr).
disp_know_strA([],[],InStr,InStr):- !.
disp_know_strA([HH|TH],[HB|TB],InStr,InS
tr):-
cl_str(HH,HB,Str), % in tr-mod.pro
concat(Instr,Str,St1),
concat(Str1,"\n",Str2),
disp_know_strA(TH,TB,Str2,OutStr).

% Printing the knowledge base ------
print_know:-
writedevice(printer),
write_know,
writedevice(screen), !.

% choose file with search pattern "NamePattern". ------
pick_file(NamePattern,FileName):-
directory_window,
dir("//",NamePattern,FileName),
removewindow.
% program-7

-------------------------------------------------------------------------
Please wait for me,
because very more...
Thanks

student

2005-08-09, 4:02 am

> ---------------------------------------------------------------------------------------------
> The book is TURBO PROLOG 高_程式_計 _致出版社


So, except for program listings, it's in Chinese?

But the program lists are in English.

Was the book translated from English into Chinese?

If it was, can you tell me the name of the author
of the original book?

Did you try to locate the original source code
that is printed in the book?

I repeat what I said in my last post: unless I can see
the original source code that you are typing in,
I will not be able to help you.

BH
chuen

2005-08-09, 9:03 am

% File: user-mod.pro program-8

/* Interacting with the user, and answering his requests about :
WHY the shell is asking the user about confirmations,
HOW the shell concluded a certain answer and
WHYNOT a given goal is a true one. */

/* To run this module by itself you need these inclusions:
code = 4000
include "glb-mod.pro"
include "ut-mod.pro"
include "stcl-mod.pro"
include "wind-mod.pro"
include "io-mod.pro"
*/
predicates
/* need_to_know will allow the user a chance to know either
HOW his goal was achieved, or he can just say he is not
interested in explanation to the system's answer. If in our
orginal goal we used "or" or ";" for disjunction. The
explanation is avialable only to the goal that was solved, this
is why in the domain declaration we have "Llist" for the goals
"answer_goals(Hlist,Hlist)." */
nondeterm need_to_know(Llist,Hlist,PAIRlist).
nondeterm check_answerB(Llist,Hlist,PAIRlist,INTEG
ER).
nondeterm know_how(Llist,Hlist,PAIRlist).
/* nondeterm reverse_list(Llist,Llist). */ % in ut-mod.pro
nondeterm know_how1(PARMlist,Llist,PAITlist).
nondeterm replace_variables(Llist,Llist,PAIRlist).
nondeterm rep_var_con(PARMlist,PARMlist,PAIRlist).
nondeterm rep_v_c(PARMlist,PARMlist,PAIRlist).
nondeterm
concat_conclusion_history(Llist,PARAMETE
R,PARAMETER,PAIRlist,INT).
/* nondeterm know_whynot(Llist,Hlist). */
nondeterm answer_yesNo(PARAMETER). % used by "know_how"
nondeterm check_answerC(INTEGER,PARAMETER).
% The inference engine ------
/* s-call is a meta call but it allows us to save the trace of the
execution in the second PARAMETER, usually called OUT-History.
By saving the trace of the execution we can answer HOW question
regarding "how an answer to a goal was reached." */
nondeterm s_call(Llist,Llist,PARMlist,PAIRlist,PAI
Rlist,INT).
nondeterm inquire(Llist,PARMlist,PAIRlist).
nondeterm check_answerA(Llist,PARMlist,PAIRlist,IN
TEGER).
nondeterm concat_history(Llist,PARAMETER,PAIRlist,
INT).
nondeterm s_calls(Llist,Llsit,Llsit,PAIRlist,PAIRl
ist,INT).
% Binding tables ------
nondeterm a_tb1(PARMlist,PARMlist,PAIRlist,PAIRlis
t,INT).
nondeterm bTBL(PARMlist,PARMlist,PAIRlist,PAIRlist
,INT).
nondeterm cTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm dTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm eTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm fTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm gTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm hTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
nondeterm jTBL(PARAMETER,PARAMETER,INT,PAIRlist,PA
IRlist).
% testing predicate
nondeterm try.
clauses
% "try" a predicate to test the metalogical predicate "s_call"
try:-
s_call([],Hist,[insurance_rate,safaa,"X"],[],Tb1,0),
write("\n Hist = ",Hist,"\n Tb1 = ",Tb1),
readln(_),
need_to_know([[insurance_rate,safaa,"X"]],[Hist],Tb1).

% Answering HOW questions ------
need_to_know(Goals,Histories,TBL):-
repeat,
how_menu(CHOICE), % in wind-mod.pro
check_answerB(Goals,Histories,TBL,CHOICE
).
% check_answerB ------
% end of consultation session
check_answerB(_,_,_,1):-
removewindow, !.
check_answerB(Goals,Histories,TBL,2):-
explaning_how_window,
know_how(Goals,Histories,TBL),
removewindow. % remove explanation window
% know_how ------
know_how([HeadGoal|RestGoals],[HeadHisto
ry|RestHistories],TBL):-
bound(HeadGoal),
rel_str(HeadGoal,GoalStr),
write("\n Do you want to know HOW:\n\n\t",GoalStr,
"\n\n is reached: "),
answer_yesNo(yes), % in ut-mod.pro, yesNo_menu in wind-mod
know_how1(HeadGoal,HeadHistory,TBL),
hnow_how(RestGoals,RestHistories,TBL).
/* IF user is not interested in knowing HOW one subgoal was cocluded
check if he is interested in knowing HOW other subgoals are
concluded. */
know_how([_|RestGoals],[_|RestHistories]
,TBL):-
clearwindow,
know_how(RestGoals,RestHistories,TBL).
% know_how1, knowing how one subgoal was reached ------
know_how1(TheGoal,[],_):-
clearwindow,
confirmed(TheGoal),
rel_str(TheGoal,GoalStr),
concat_list(["\n Your goal, that is \n\n\t",GoalStr,
"\n\n was confirmed by you."],Str),
display(Str), !.
know_how1(TheGoal,History,TBL):-
reverse_list(History,VH),
clearwindow,
rel_str(TheGoal,GoalStr),
/* This will replace all variables in the history clauses
with constant values is they were bound during execution,
constant values for the variables are found in the TBL */
replace_variables(VH,CH,TBL),
concat_conclusion_history(CH,"",HowStr,TBL,_),
concat_list(["\n Your goal was: \n\n\t",GoalStr,HowStr],Str),
display(Str).
% Reporting the history of execution ------
concat_conclusion_history([H],InStr,OutS
tr,BTBL,Num):-
confirmed(H),
rel_Str(H,StrBound),
a_tbl(S,H,BTBL,_,Num),
rel_str(S,StrVar),
concat_list([INStr,
"\n\n the only left subgoal, that is:\n ---> ",
StrVar,
"\n is satisfied with the confirmed fact:\n ---> ",
StrBound,
"\n\n\t\t ______________________________ "],
OutStr), !.
/* The last clause in the history is the last subgoal predicate in
its bound form, that is if a rule of the form:
likes(X,Y) if likes(X,Z) and likes(Z,Y).
then likjes(Z,Y) is the last subgoal need to be satisfied before
the whole rule is satisfied and the conclusion likes(X,Y) is
reached. */
concat_conclusion_history([H],InStr,OutS
tr,BTBL,Num):-
rel_str(H,StrBound),
a_tbl(S,H,BTBL,_,Num),
rel_str(S,StrVar),
concat_list([INStr,
"\n\n the only left subgoal, that is:\n ---> ",
StrVar,
"\n is satisfied with the fact:\n ---> ",
StrBound,
"\n\n\t\t ______________________________ "],
OutStr), !.
/* If a fact in the knowledge base was confirmed by the user after
being asked by the system, then this confirmation should show
on the explanation of the reasoning process. */
concat_conclusion_history([HHist|THist],
InStr,OutStr,BTBL,Num):-
confirmed(HHist),
rel_Str(HHist,Str1),
concat_list([INStr,
"\n And you have confirmed the fact:\n ---> ",
Str1],Str2),
concat_conclusion_history(THist,Str2,Out
Str,BTBL,Num), !.
/* Otherwise the subgoal or goal was satisfied by a fact in the
original knowledge base. */
concat_conclusion_history([HHist|THist],
InStr,OutStr,BTBL,Num):-
cl(HHist,[]),
cl_str(HHist,[],Str1),
concat_list([INStr,
"\n And form the knowledge base I have that:\n ---> ",
Str1],Str2),
concat_conclusion_history(THist,Str2,Out
Str,BTBL,Num), !.
/* Otherwise the subgoal or goal was satisfied by a rule in the
original knowledge base. */
concat_conclusion_history([HHist|THist],
InStr,OutStr,BTBL,Num):-
a_tbl(Head,HHist,BTBL,_,Num),
cl(Head,Body),
rel_str(HHist,Str1),
rel_str(Head,Str2),
cl_str(Head,Body,Str3),
concat_list([INStr,
"\n And I concluded that:\n\t",
Str1,"\n in otherwords **** ",Str2, " ****",
"\n By using: \n --->", Str3],Str4),
concat_conclusion_history(THist,Str4,Out
Str,BTBL,Num), !.
concat_conclusion_history([HHist|THist],
InStr,OutStr,BTBL,Num):-
cl(HHist,Body),
rel_str(HHist,Str1),
cl_str(HHist,Body,Str2),
concat_list([INStr,
"\n And I concluded that:\n\t",Str1," **** ",
"\n By using: \n --->", Str2],Str3),
concat_conclusion_history(THist,Str3,Out
Str,BTBL,Num), !.
% replace a variable by its constant value if any ------
replace_variables([],[],_):- !.
replace_veriables([VH|VT],[CH|CT],TBL):-
rep_var_con(VH,CH,TBL),
replace_variables(VT,CT,TBL).
rep_var_con([Name|VParms],[Name|CParms],
TBL):-
rep_v_c(VParms,CParms,TBL).
rep_v_c(([],[],_).
rep_v_c([V|T],[C|T1],TBL):-
variable(V),
member(pair(V,C,_),TBL),
rep_v_c(T,T1,TBL), !.
rep_v_c([H|T],[H|T1],TBL):-
rep_v_c(T,T1,TBL).

/* Saving the solution path while executing
And answering WHY question .........

What inquire does is to ask the user about if some condition holds
or not. It asks about the truth of a certain condition in a rule
when it cannot find a fact or rule that satisfies such condition.

For example if we have the following knowledge base:
likes(adam,eve).
likes(X,Z) if
likes(X,Y) and
likes(Y,Z).
and we have the goal: likes(adam,apple).
Inquire will prompt the user to answer by "yes","no", or "why"
for the following question:
is it true that likes(eve,apple). */
inquire(History,P,BTBL):-
rel_str(P,Str),
write("\n Is it true that ",Str,": "),
why_menu(CHOICE), !,
% the cut here helps when the CHOICE is 2 and failure effect
% is wanted in order to fail the predicate inquire itself
check_answerA(History,P,BTBL,CHOICE).
% check_answerA ------
% When CHOICE is pressing the escape key "exit" is requested
check_answerA(_,_,_,0):- exit.
% When CHOICE is 1 then answer is "yes"
check_answerA(_,P,_,1):-
assertz(cl(P,[])),
assertz(confirmed(P)),
write("yes \n".
% When CHOICE is 2 then answer is "no"
check_answerA(_,_,_,2):-
write("no \n"), fail.
/* When failure takes place, we need to backtrack and try to
find alternative solutions, and if necessary ask the user
(inqurie) again about their truth

When the user wants to know why the system is asking about the
truth of a certain fact, the system responds with a display of
the rule that one of its condition is the fact under consideration
..... IT is possible to make the user continue asking that "all
this was first of all because of the user goal which started the
inference mechanism." */
check_answerA([],P,BTBL,3):-
explaning_why_window,
rel_str(P,Pstr),
concat("\n I am trying to show that: ",Pstr,Str1),
concat(Str1,"\n So Please answer accordingly: ",Str2),
write(Str2),
inquire([],P,BTBL),
removewindow.
check_answerA(History,P,BTBL,3):-
explaning_why_window,
a_tbl(S,P,BTBL,_,Num),
cl(H,B),
member(S,B),
a_tbl(H,HS,BTBL,_,Num),
rel_str(HS,Hstr),
concat("I am trying to show that ",Hstr,Str1),
concat(Str1,"\n By using: \n\t",Str2),
cl_str(H,B,Str3),
concat(Str2,Str3,Str4),
concat_history(History,Str5,BTBL,Num),
display(Str6),
inquire(History,P,BTBL),
removewindow. % calling inquire causes the
% go back to the original inquiry
% and ask for confirmation or denial
% for the fact "P"
% Reporting the history of execution
% "concat_history" is same as "report" in GENI
concat_history([H],Str,_,_):-
rel_str(H,Str1),
concat("\n Since your original goal was: ",Str1,Str), !.
concat_history([HHist|THist],Str,BTBL,Nu
m):-
cl(HHist,[]),
cl_str(HHist,[],Str1),
concat("\n Since I have shown that: ",Str1,Str2),
concat_history(THist,Str3,BTBL,Num)
concat(Str2,Str3,Str), !.
concat_history([HHist|THist],Str,BTBL,Nu
m):-
a_tbl(SubGoal,HHist,BTBL,_,Num),
cl(Head,Body),
member(SubGoal,Body),
rel_str(HHlist,Str1),
rel_str(SubGoal,Str2),
cl_str(HHist,[],Str1),
concat("\n I have shown that: ",Str1,Str3),
concat(Str3,"\n in otherwords - ",Str4),
concat(Str4,Str2,Str5),
concat(Str5," -",Str6),
concat(Str6,"\n By using: ",Str7),
cl_str(Head,Body,Str8),
concat(Str7,Str8,Str9),
concat_history(THist,Str10,BTBL,Num)
concat(Str9,Str10,Str), !.
concat_history([HHist|THist],Str,BTBL,Nu
m):-
a_tbl(SubGoal,HHist,BTBL,_,Num),
cl(SubGoal,Body),
rel_str(HHlist,Str1),
rel_str(SubGoal,Str2),
concat("\n I have shown that: ",Str1,Str3),
concat(Str3,"\n in otherwords - ",Str4),
concat(Str4,Str2,Str5),
concat(Str5," -",Str6),
concat(Str6,"\n By using: ",Str7),
cl_str(SubGoal,Body,Str8),
concat(Str7,Str8,Str9),
concat_history(THist,Str10,BTBL,Num)
concat(Str9,Str10,Str).
% Getting a Yes/No answer ------
answer_yesNo(Answer):-
yesNo_menu(CHOICE), % in "wind-mod.pro
check_answerC(CHOICE,Answer).
check_answerC(1,yes).
check_answerC(2,no).
/* The Inference Engine

It is also possible to write facts and rules the using the database
predicate "cl" and then by a call to s_call these facts and
rules are executed. For example the fact "connects(kitchen,bath)"
can be written:
cl([connects,kitchen,bath],[]).
right in the program itself, not in an external file, and then
get executed when matching a goal like this one:
s_call([],[connects,kitchen,bath],[],X,0
),

s_call & s_calls ------
(1) If the goal "P" matchs a fact in the KB equate In and Out
history. */
s-call(History,[P|History],P,In,Out,Num):-
cl(S,[]),
a_tbl(S,P,In,Out,Num), !.
/* (2) If goal "P" is not already saved in history then add it to
the InHistory list, the subgoal "not(member(P,InHistory))"
lets us make sure that "P" is not saved twice in History.
Then we will continue in trying to solve "P" by matching
it with a rule in the KB, remember a rule in clausal
form is "cl(S,[H|B])". If "P" matchs the head of the rule
"S" then add "P" to history and try solving the Body "[H|B]"
by calling "s_calls." */
s_call(InHistory,OutHistory,P,In,Out,Num
):-
not(member(P,InHistory)),
cl(S,[H|B]),
a_tbl(S,P,In,TBLA,Num), !,
s_Calls([P|InHistory],OutHistory,[H|B],T
BLA,Out,Num), !.
/* (3) After trying (2) and failing, we know that "P" is
already existing in the "InHistory" list. So giving that
"P" is called again at a different level than the earlier
"P" call we need to change the "recursion-level" number
"Num" before trying to solve "P", matching "P" with a head
of a clause in KB. We change "Num" to "NumA=Num+1." */
s_call(InHistory,OutHistory,P,In,Out,Num
):-
not(member(P,InHistory)),
cl(S,[H|B]),
NumA = Num + 1,
a_tbl(S,P,In,TBLA,NumA), ,
s_calls([P|InHistory],OutHistory,[H|B],T
BLA,Out,NumA), !.
/* (4) if 1,2,3 all fails and the InHistory list is still empty
then there is no clause in KB with which we can "P" match
its head. So we fail the cluase and tries to ask the user
to supply a confirmation, this means we use clause 5. */
s_call([],[],_,_,_,_):- !, fail.
/* (5) By passing the "InHistory" to "inquireA" we can answer
the user's "WHY" questions. As the "InHistory" represents.
The history of execution up to the point when the system
needs to ask the user to confirm some piece of information.
Remember that "InHistory" was built from an empty list
"[]" which we inputed at the start of the execution of the
goal. The "OutHistory" on the other hand is only gets
instantiated at the end, when the goal is reached. One
exception is that the "OutHistory" is returned as a result
of the successful execution of the goal. It is used to
answer "HOW" questions. One important thing to remember,
"OutHistory" starts with the fact that represents the ground
on which our goal is satisfied, "OutHistory" last member is
the goal we started with. To answer "HOW" questions we have
to reverse the "OutHistory" first, to get the right chain
of facts and rules that takes us from the goal to the proof. */
s_call(InHistory,OutHistory,P,In,Out,Num
):-
inquire(InHistory,P,In),
s_Call(InHistory,OutHistory,[H|B],TBLA,O
ut,Num), !.
/* Solving a list of sub-goals forming the body of a rule
(1) When there no more goals to slove, InHistory = OutHistory */
s_calls(History,History,[],TBL,TBL,_):- !.
/* (2) When there more than on condition in the body of a rule,
they are considered as a list [SH|ST] and solved in
a recursive fashion. */
s_calls(InHistory,OutHistory,[SH|ST],In,
Out,Num):-
a_tbl(SH,P,In,TBLA,Num),
s_call(InHistory,_,P,TBLA,TBLB,Num),
s_calls([P|InHistory],OutHistory,ST,TBLB
,Out,Num), !.
% Binding tables with multiple variable uses
a_tbl([Name|Slist],[Name|Vlist],In,Out,N
um):-
bTBL(Slist,Vlist,In,Out,Num).
bTBL([],[],TBL,TBL,_).
bTBL([S|ST],[V|VT],In,Out,Num):-
cTBL(S,V,Num,In,OutA),
bTBL(ST,VT,OutA,Out,Num).
cTBL(XS,V,Num,In,Out):- % "V" here can be free or bound
bound(Xs),
variable(Xs), % "Xs" is a string starts with capital letter
dTBL(Xs,V,Num,In,Out).
cTBL(Ss,V,Num,In,Out):- % "V" here can only be bound
bound(V),
variable(V), % "Ss" is a string acting as a constant
gTBL(Ss,V,Num,In,Out), !.
cTBL(Ss,Fv,Num,In,Out):-
free(Fv),
hTBL(Ss,Fv,Num,In,Out).
cTBL(Fs,Bv,Num,In,Out):-
free(Fs),
jTBL(Fs,Bv,Num,In,Out).
cTBL(S,S,_,TBL,TBL).
dTBL(Xs,V,Num,In,Out):-
bound(V),
eTBL(Xs,V,Num,In,Out).
dTBL(Xs,Fv,Num,In,Out):-
free(Fv),
fTBL(Xs,Fv,Num,In,Out).
eTBL(Xs,Bv,Num,TBL,TBL):-
member(pair(Xs,Bv,Num),TBL).
eTBL(Xs,Bv,Num,In,[pair(Xs,Bv,Num)|In]):
-
not(member(pair(_,Bv,Num),In)).
fTBL(Xs,_,Num,[],[pair(Xs,Xs,Num)]).
fTBL(Xs,V,Num,[pair(Xs,V,Num)|R],[pair(X
s,V,Num)|R]).
fTBL(Xs,V,Num,[PAIR|In],[PAIR|Out]):-
fTBL(Xs,V,Num,In,Out).
gTBL(Ss,Xv,Num,[],[pair(Xv,Ss,Num)]).
gTBL(Ss,Xv,Num,[pair(Xv,Xv,Num|R)],[pair
(Xv,Ss,Num)|R)]).
gTBL(Ss,V2,Num,[pair(V1,V2,Num|R)],
[pair(V1,Ss,Num),pair(V2,Ss,Num)|R]).
gTBL(Ss,Xv,Num,[PAIR|In],[PAIR|Out]):-
gTBL(Ss,Xv,Num,In,Out).
hTBL(S,S,_,[],[]).
hTBL(S,S,Num,[pair(Xs,Xs,Num)|R],[pair(X
s,S,Num)|R]).
hTBL(S,Fv,Num,[PAIR|In],[PAIR|Out]):-
hTBL(S,Fv,Num,In,Out).
jTBL(S,S,_,[],[]).
jTBL(Fs,Bv,Num,[pair(Fs,Bv,Num)|R],[pair
(Fs,Bv,Num)|R]).
jTBL(Bv,Bv,Num,[pair(Fs,Bv,Num)|R],[pair
(Fs,Bv,Num)|R]).
jTBL(Fs,Bv,Num,[A|In],[A|Out]):-
jTBL(Fs,Bv,Num,In,Out).
% program-8

chuen

2005-08-09, 9:03 am

% File: stcl-mod.pro program-9

/* The consultation Module
This module is called by the "main-mod.pro" module

This the module where predicates like "get_goal", "answer_goal"
and others are implemented to allow the user to ask questions
about a certain domian of expertise. */
predicates
nondeterm get_goal(PARAMETER).
nondeterm topict(PARAMETER).
nondeterm info(PARAMETER).
nondeterm list_domains.
% nondeterm no_dup(PARMlist,PARMlist). % in ut-mod.pro
% Answering goals and knowing HOW ------
nondeterm answer_goals(Hlist,Hlist).
nondeterm answer_subgoals(Llist,Hlist,PAIRlist,PAI
Rlist).
nondeterm display_answers(Llist,PAIRlist).
nondeterm display_variable_value(PARMlist,PAIRlist
).

clauses
/* Get a user query ( GOAL ) ------

When a KB file is already in memory, a "topic" fact/s are
asserted and such fact/s will tells us the kind of domains
we like to have questions about. */
get_goal(GoalStr):- % The goal is entered as a string
clearwindow,
topict(Topic),
repeat,
write("You may ask questions about certain area of interest\n"),
write("(e.g.",Topic,") \n"),
write("or Enter '?' for information on how to enter a goal."),
write("\nEnter goal/s >> "),
readln(GoalStr),
info(GoalStr), !.
% topict ------
topict(Topic):-
cl([topic,Topic],[]). % check if any "topic" fact is already known
topict(Topic):-
write("Enter a name that represents"),
write("\n this knowledge domain\n : "),
readln(Topic),
assert(cl([topic|Topic],[])).
% info ------
info("?"):-
info_window,
write("Enter the type of domain you have a question about."),
list_domains,
write("\n\n press any key "),
readchar(_),
removewindow,
clearwindow,
fail.
info(X):-
X >< "?".
% list_domains ------
list_domains:-
write("\nCurrently in the knowledge base domain/s is/are:\n\n"),
findall(Relation,cl([Relation|_],_),RelL
ist),
no_dup(RelList,DomainsList), % in ut-mod.pro
write_list(DomainsList), !.
list_domains:-
write("\n There are no asserted clauses in the knowledge base"),
write("\n Please go back to main menu to load a knowledge base"),
write("\n file.").
/* answer_goals ------
"answer_goals" answer a conjunction disjunction of sub-goals

When having a list of predicate relations and we want to execute
them, the predicate "answer_goals" does that for us. What
"answer_goals" does is that it takes a list of form:
[GOAL1,GOAL2,etc...] where goals such as:
can be a single goal --> GOAL1 =3D [[Likes,safaa,design]]
or
can be a conjuncted subgoals --> GOAL2 =3D [SUB1,SUB2]
Sub1 =3D [likes,safaa,art] and
Sub2 =3D [not,likes,safaa,drugs]
When Goal1 succeeds, the rest of the goals (GOAL2,etc...) are not
tested. Otherwise if GOAL1 fails, GOAL2 will be tried. So in fact
the list of goals is a list of disjuncted goals, goals connected
by an "or".

If no goal exist or no previous goal succeeds return failure */
answer_goals([],[]):-
!,
write("\n\t FAILURE -- (Sorry no goal exist\\succeed)"),
readln(_),
fail.
% If first goal succeeds ends the reasoning and return answer
answer_goals([Hgoal|_],History):-
answer_subgoals(Hgoal,History,[],TBL),
display_answers(Hgoal,TBL),
need_to_know(Hgoal,History,TBL) !. % in "user-mod.pro"
% Otherwise try satisfy next goal.------
answer_goals([_|RestGoals\,History):-
answer_goals(RestGoals,History).
/* Answer_subgoals ------
"answer_subgoals" takes a list of conjuncted goals and execute
them one after the other. The predicate "answer_subgoalss" is
used to process our goal. The "FirstSubGoal" will be examined
by "s_call" and if necessary it will "enquire" the user to
provide answers.
"s_call" is "cl-mod.pro" and "inquire" is in "use-mod.pro" */
answer_subgoals([],[],Tbl,Tbl).
answer_subgoals([FirstSubGoal|Rest],[HHi
st|HRest],InTbl,OutTbl):-
s_call([],HHist,FirstSubGoal,InTbl,OldOu
tTbl,0),
answer_subgoals(Rest,HRest,OldOutTbl,Out
Tbl), !.
% display_answers ------
display_answers([],_).
display_answers([[_|Parms]|Rest],TBL):-
display_variable_value(Parms,TBL),
display_answers(Rest,TBL).
display_variable_value(_,[]):-
write("\n Goal Proved\n"), !.
display_variable_value([Var|Rest],[pair(
Val,Val,_)|RestPairs]):-
variable(Var),
write("\n ",Var," =3D ",Val),
display_variable_value(Rest,RestPairs), !.
display_variable_value([Var|Rest],[_|Res
tPairs]):-
variable(Var),
display_variable_value([Var|Rest],RestPa
irs), !.
display_variable_value([_|Rest],TBL):-
display_variable_value(Rest,TBL), !.
% program-9

------------------------------------------------------
TURBO PROLOG =E9=AB=98=E7=AD=89=E7=A8=8B=E5=BC=8F=E8=
A8=AD=E8=A8=88 =E6=
=A0=BC=E8=87=B4=E5=87=BA=E7=89=88=E7=A4=
BE
1989. =E8=A8=B1=E6=B0=B8=E5=81=89=E7=B7=A8=E8=
AD=AF, =E9=BB=83=E4=B8=89=E7=
=9B=8A=E7=B7=A8=E8=AD=AF,
I have not English version.
Now, I am typing , May be finishing with one w.
you will not be able to help you.
I understand. Thanks,
the name of the author of the original book?
I don=E2=80=99t know, I=E2=80=99m sorry.
locate the original source code that is printed in the book?
It have a less of error.
I try a correct it.

I am very tired.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com