I have a Prolog database file (test_inserts.p) that I used to insert all my data.
I also have a Prolog query file (test_queries.pl) that has all of the Prolog queries I wrote up to receive specific information from my database.
I was wondering how to actually use the test_queries.pl queries against my test_inserts.p database file when using gprolog? I was hoping there would be a way to load both at the same time, and somehow be able to command which query to run, instead of having to re-type each query that I wanted to run....
Prolog queries work by pattern matching. The query pattern is called a goal. If there is a fact that matches the goal, then the query succeeds and the listener responds with 'yes. ' If there is no matching fact, then the query fails and the listener responds with 'no.
Prolog is an elegant language for database queries. In fact if one constrains Prolog programs to use only atoms, integers and reals (no lists or complex terms) and disallows recursive definitions, one gets a database language that is equivalent to a powerful subset of SQL.
Dynamic database can change dynamically at execution time and are of two types. Type1: created at each execution. It grows, shrinks and is deleted at the end of program. ● This type of database is no longer available after program finishes its execution and is called working memory.
I've used initialization/1
ISO directive in test_queries.pl
to get the effect you see at bottom.
test_queries.pl
test :-
findall(_, (a(X,Y), format('~w ~w~n', [X,Y])), _).
:- initialization([test_inserts]).
:- initialization(test).
test_inserts.pl
a(X,Y) :- append(X,Y,[1,2,3]).
then call gprolog with --consult-file
gprolog --consult-file test_queries.pl
GNU Prolog 1.4.0
By Daniel Diaz
Copyright (C) 1999-2011 Daniel Diaz
compiling /home/carlo/test_queries.pl for byte code...
/home/carlo/test_queries.pl compiled, 5 lines read - 659 bytes written, 28 ms
compiling /home/carlo/test_inserts.pl for byte code...
/home/carlo/test_inserts.pl compiled, 2 lines read - 379 bytes written, 30 ms
[] [1,2,3]
[1] [2,3]
[1,2] [3]
[1,2,3] []
| ?-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With