90 likes | 353 Views
Prolog uses the write predicate to present output to the user. Prolog uses the read predicate to read Terms from standard input. Standard involve must be followed by a period. LPA Prolog has the ability to create and manipulate dialog boxes. test :- write('Enter an atom'), nl,
E N D
Prolog uses the write predicate to present output to the user. Prolog uses the read predicate to read Terms from standard input. Standard involve must be followed by a period. LPA Prolog has the ability to create and manipulate dialog boxes. test :- write('Enter an atom'), nl, read(Atom), atom(Atom), assertz(Atom), call(Atom), listing. Prolog - Input and output NOTE: Some new built in predicates are introduced here.
You can use the listing predicate to list all dynamic predicates loaded. Alternately you can use a combination of write and the fail predicate. See capitals.pl capital_of(georgia,atlanta). capital_of(california,sacramento). capital_of(florida,tallahassee). capital_of(maine,augusta). print_capitals :- capital_of(State,City), write(City), write(‘ is the capital of), write(State), nl, fail. Listing the contents
To load clauses from the listing file into the Prolog interpreter use consult or reconsult ensure_loaded can be used to automatically load files when a buffer is being consulted. You can use the compiler directive :- in front of any of these commands and they will be carried out as a buffer is being re-consulted. Loading Prolog terms
This see predicate is used to stream input from a file. After the see predicate all reads refer to the input stream from the file. seen is used to close input stream. That tell predicate is used to redirect output to a file. All subsequent writestatements are redirected to the file named in tell predicate. told closes the output stream. File handling You can see these features in learner.pl used with kb.pl
A sample Expert system • See car.pl • Basic Components • Inference Engine (Prolog’s built in backward chaining). • Knowledge base defect_may_be/1. • Knowledge acquisition mechanism ask_questions/1. • Recording what the user answers stored_answer/2. • An explanation facility explain/1.