1 / 5

Prolog - Input and output

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,

Download Presentation

Prolog - Input and output

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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

  3. 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

  4. 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

  5. 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.

More Related