Did you know ... Search Documentation:
Pack logtalk -- logtalk-3.77.0/examples/named_databases/SCRIPT.txt

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. ________________________________________________________________________

% start by loading the example:

| ?- logtalk_load(named_databases(loader)). ...

% create a new named database:

| ?- db_create(my_db). yes

% add some facts to the new database:

| ?- db_dynamic(my_db, foo/1). yes

| ?- db_assertz(my_db, foo(1)), db_assertz(my_db, foo(2)), db_assertz(my_db, foo(3)). yes

% prove goals using the named database:

| ?- db_call(my_db, foo(X)). X = 1 ; X = 2 ; X = 3 yes

| ?- db_once(my_db, foo(X)). X = 1 yes

% save all dynamic predicates in the database to a file:

| ?- db_save(my_db, 'my_db.pl'). yes

% clear the named database:

| ?- db_clear(my_db). yes

% load the saved file into a different database:

| ?- db_create(foo_db), db_load(foo_db, 'my_db.pl'). yes

% check that the saved facts are there by retracting them one by one:

| ?- db_retract(foo_db, foo(X)). X = 1 ; X = 2 ; X = 3 yes