Saturday, 7 September 2013

Prolog - How to write all prolog answers to .txt file?

Prolog - How to write all prolog answers to .txt file?

man(alan). man(john). man(george).
list_all:- man(X), write(X), fail.
Question ?-list_all gives the answer: alan john george false
So i have all the men from the database. It works! My problem: I want to
get the same list, but exported to .txt file. I tried to use this code to
do this:
program :- open('file.txt',write,X), current_output(CO), set_output(X),
man(X), write(X), fail,
close(X), set_output(CO).
The effect is: Program gives answer false and text: alan john george are
not in txt file - because of using "fail" predicate.
Is there any option to get all this list in .txt file (writing all options
which are in database) without using "fail" predicate?
How can I do this? Please help me

No comments:

Post a Comment