Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:10:31+00:00 2026-06-05T01:10:31+00:00

I have a prolog database file with lots of facts knowledge.pl . For example:

  • 0

I have a prolog database file with lots of facts knowledge.pl. For example:

father_of(joe,paul).
father_of(joe,mary).
mother_of(jane,paul).
mother_of(jane,mary).
male(paul).
male(joe).
female(mary).
female(jane). % and so on.

This file is consulted (consult/1) every time my program is executed again.

I would like to be able to insert, modify and delete the facts I want (some of them directly, some others that meet some specific conditions) by writing or deleting directly within this database text file.

something like assertz, retract and retractall but modifying this text file so that the changes remain permanently there.

how can I do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:10:33+00:00Added an answer on June 5, 2026 at 1:10 am

    you can either create the facts you want and write them to the (same) file or modify the database and then save it in the file.

    the difference is that with the first approach you will have the db of the old file loaded while the second approach will change it during execution.

    From the way you phrased the question I assume that you want to do the second; to do this you should:

    1)declare all the predicates that you want to change as dynamic
    2)assert,retract etc during execution
    3)write the new database to the file. you can use listing/1

    To write you can do something like:

    tell(knowledge),
    .....
    told.
    

    or you can use some other io predicates. maybe using set_prolog_IO/3 would be the simplest way.

    Now, if you wanted the first, you should construct the predicates (probably using the univ operator) or other string manipulation predicates and then write them to a file

    EDIT:

    there is listing/0 but that will list all the predicates loaded (something you might not want).
    after some searching I found source_file/2; so you can do something like

    findall(X,source_file(X,FileName),L).
    

    note that source_file/2 requires the absolute filename. you can use absolute_file_name/2 to get it
    the way source_file/2 formats the predicate is a bit weird (i was expecting something like foo/1) but it looks like you can give it to listing/1 and it works fine so you can do something like:

    save(FileName):-
        absolute_file_name(FileName,Abs),
        findall(X,source_file(X,Abs),L),
        tell(FileName),
        maplist(listing,L),
        told.
    

    on the other hand, you can always have a list with the predicates you want to store somewhere in the file

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Prolog file (Hanoi.pl) containing the code for solving the Hanoi Towers
I have a large Prolog program with lots of predicates. I need to connect
I have a sictus prolog file (.pl-file) that I would like to export as
I have some prolog. The lessThanTen and example predicates work as expected however the
Complete prolog beginner here. Let's say I have a prolog knowledge base which contains
I have the next two facts loaded in my prolog interpreter: foo(U+V,1). foo(U*V,2). Now
Assume that the following facts are already entered into the Prolog database: father(X, Y)
I have the following prolog expression in my file which is pretty self explanatory.
I have a database in prolog, all I want to do is enuamrate through
I have a problem, while creating a question answer Prolog file. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.