I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.
I need to know if there is a data structure in SWI-Prolog that allows me to emulate a queue or linked list that I can access from “either end”. By either end I mean access the elements linearly from the oldest element to the newest, or conversely, from the newest element to the oldest.
My app maintains a history of each transaction with the user. It needs to examine that history but most of the time it just needs to access a few of the most recent transactions, reading in reverse chronological order, starting with the newest transaction and iterating towards the oldest. Every now and then it will need to access that history in the opposite direction, from the oldest to the newest.
So I need to know what is the SWI-Prolog equivalent of a queue or linked list that one can traverse in either direction? If no such thing exists, I need to know how to get the same effect from the Prolog database.
The worst situation is if I have to read from the beginning of the history all the way to the most recent transactions in order to get just those recent transactions. It is most convenient if I can read the elements in reverse chronological order without having to sort them. I don’t know enough about the Prolog database to know in what order elements are stored in the database when you make assertions to the same predicate and subsequently make a query with backtracking upon that predicate.
So, if there is no such data structure in SWI-Prolog that does what my app needs here, how can I use
asserta/assertz to add elements in the correct order so that when I do a query to the predicate, I get the newest element first and upon backtracking, iterate from the newest transaction in a direction iterates progressively towards the oldest element ever asserted to the database?