Is ChatGPT just wrong about library(persistency)?

Here is a prompt (question) asked of ChatGPT Feb 13 Version.

What does SWI-Prolog library(persistency) do?

ChatGPT Feb 13 Version Completion

The SWI-Prolog library(persistency) provides a framework for storing and loading Prolog terms from disk, which allows data to persist across multiple program runs.

The persistency library is designed to provide a simple and efficient solution for storing large amounts of data that may not fit entirely in memory. It achieves this by using a combination of memory-mapped files and Prolog term serialization to write and read data to and from disk.

The persistency library provides two main predicates: db_attach/2 and db_sync/1.

The db_attach/2 predicate is used to attach a Prolog database to a file on disk. Once attached, the database can be updated and queried using normal Prolog predicates. Changes made to the database are automatically stored on disk, and can be retrieved on subsequent program runs.

The db_sync/1 predicate is used to synchronize any changes made to the database with the file on disk. This ensures that all changes are safely stored on disk and can be retrieved in subsequent program runs.

In summary, the library(persistency) in SWI-Prolog provides a way to store and retrieve Prolog data structures to disk, which can be useful for applications that need to persist data between program runs.


The part that AFAIK is just wrong is in this statement:

The persistency library is designed to provide a simple and efficient solution for storing large amounts of data that may not fit entirely in memory. It achieves this by using a combination of memory-mapped files and Prolog term serialization to write and read data to and from disk.

My understand of library(persistency) from actual use is that the Prolog file (*.pl) is a journal of assert and retract statements that are played back when the the db is attached. Either all the statements run to completion and all of the data is in memory or an error occurs. Stating storing large amounts of data that may not fit entirely in memory is just wrong.

I also have no idea where using a combination of memory-mapped files came from. I have never seen a memory mapped file being created for this on Windows.

Can Jan W. confirm that my understanding is correct? Thanks. :slightly_smiling_face:

Just check the code. Quite some is right, but it just about being able to restore a predicate after restarting Prolog and doesn’t use memory mapping. It is indeed just a journal with some support to clean the journal, getting rid of assert/retract combinations that cancel each other.

1 Like