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 an option to get all the items in the list into a .txt
file (writing all options which are in database) without using fail
predicate?
How can I do this? Please help me.