Did you know ... Search Documentation:
Pack logtalk -- logtalk-3.85.0/examples/named_databases/NOTES.md

This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2023 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

To load this example and for sample queries, please see the SCRIPT.txt file.

This example implements "named databases", providing a prototype implementation for a portable API based on Lean Prolog implementation of this functionality. The goal is to provide the fastest possible loading time for encapsulated data. The API supports loading data from a file into a named database, saving a named database to a file, together with a set of predicates derived from the standard Prolog built-in database predicates. The performance advantage of using a Prolog module over a Logtalk object is that, for the supported backend compilers, the module file is compiled in one step without requiring generating and compiling an intermediate file as (must be) done by the Logtalk compiler when loading a source file (for portability across compiler backends).

Named databases are currently implemented for a subset of the Prolog systems supported by Logtalk: ECLiPSe, SICStus Prolog, SWI-Prolog, and YAP.

Caveat: most Prolog systems cannot list clauses for static code. Some systems, such as SWI-Prolog, do allow listing of static code by default but can be set to prevent it. One important consequence is that, although it is possible to load files with static predicates into named databases, saving them will only save the dynamic predicates. I.e. named databases loading static resources should be regarded as read-only databases.

A hook object is provided for optimizing calls to the named database API predicates within object and categories.

Being a programming example, there isn't currently any error checking on the API predicate arguments.

API description:

[100, 98, 95, 99, 114, 101, 97, 116, 101, 40, 68, 97, 116, 97, 98, 97, 115, 101, 41]
Creates a new named database
[100, 98, 95, 100, 121, 110, 97, 109, 105, 99, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 80, 114, 101, 100, 105, 99, 97, 116, 101, 41]
Declares a new dynamic predicate
[100, 98, 95, 97, 98, 111, 108, 105, 115, 104, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 80, 114, 101, 100, 105, 99, 97, 116, 101, 41]
Abolishes a dynamic predicate
[100, 98, 95, 97, 115, 115, 101, 114, 116, 97, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 67, 108, 97, 117, 115, 101, 41]
Asserts a clause for a dynamic predicate
[100, 98, 95, 97, 115, 115, 101, 114, 116, 122, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 67, 108, 97, 117, 115, 101, 41]
Asserts a clause for a dynamic predicate
[100, 98, 95, 114, 101, 116, 114, 97, 99, 116, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 67, 108, 97, 117, 115, 101, 41]
Retracts a matching clause for a dynamic predicate
[100, 98, 95, 114, 101, 116, 114, 97, 99, 116, 97, 108, 108, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 72, 101, 97, 100, 41]
Retracts all clauses for a dynamic predicate with a matching head
[100, 98, 95, 99, 108, 97, 117, 115, 101, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 72, 101, 97, 100, 44, 32, 66, 111, 100, 121, 41]
Retrieves clauses for dynamic predicates in the named database
[100, 98, 95, 99, 97, 108, 108, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 71, 111, 97, 108, 41]
Proves a goal using the predicate clauses in the named database
[100, 98, 95, 111, 110, 99, 101, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 71, 111, 97, 108, 41]
Proves a goal once using the predicate clauses in the named database
[100, 98, 95, 108, 105, 115, 116, 105, 110, 103, 40, 68, 97, 116, 97, 98, 97, 115, 101, 41]
Lists all dynamic predicates in the named database
[100, 98, 95, 108, 111, 97, 100, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 70, 105, 108, 101, 41]
Loads a Prolog file into a named database
[100, 98, 95, 115, 97, 118, 101, 40, 68, 97, 116, 97, 98, 97, 115, 101, 44, 32, 70, 105, 108, 101, 41]
Saves all dynamic predicates to a file
[100, 98, 95, 99, 108, 101, 97, 114, 40, 68, 97, 116, 97, 98, 97, 115, 101, 41]
Abolishes all dynamic predicates