I have a Prolog file where I'm consulting a knowledge base and adding my own predicates. I want to have a predicate that saves the entire updated knowledge base to a text file.
I've tried doing this with listing/0
, but it seems I can't change its output stream. I could, technically, write each clause separately to the file with portray_clause/2
, but I'd like to achieve this in a more elegant way.
Is there a predicate/predicate combination that will allow me to do this?
EDIT: I managed to output the entire knowledge base to a file like so:
tell('newkb.txt'), listing, told.
This achieves what I wanted to do, with a slight drawback: the new newkb.txt
file contains a few automatically generated clauses that I'd rather not keep, if possible.
If this is the only/best solution, so be it. But, if there's a way to export the knowledge base, and only the knowledge base, I'd really like to hear it.
Thank you.
Project.pl
. Inside it I have::- ['knowledgebase.txt'].
predicate_1(...) :- ... .
predicate_2(...) :- ... .
, etc. I want to write a predicate that will output both the knowledge base that is being consulted and the predicates I've written in theProject.pl
file to another file. Actually, though I've been looking for a solution for almost an hour, as soon as I posted this question, I managed to do (almost exactly) this in the following way:tell('newkb.txt'), listing, told.
. This does add a lot of other generated predicates, however. – Andrétell('newkb.txt'), listing(pred1), listing(pred2), ..., listing(pred-n), told.
– lurkerlisting_of_just_my_stuff
predicate. – lurker