简单的PROLOG问题:如何测试对您的Prolog数据库的多个查询? [英] Simple PROLOG issue: How do you test multiple queries against your Prolog database?
问题描述
我有一个Prolog数据库文件(test_inserts.p),我用来插入我的所有数据。
I have a Prolog database file (test_inserts.p) that I used to insert all my data.
我也有一个Prolog查询文件(test_queries.pl)有我所写的所有Prolog查询从我的数据库收到具体的信息。
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.
我想知道如何实际使用test_queries.pl查询我的test_inserts.p数据库文件时使用 gprolog?我希望有一种方法同时加载两者,并以某种方式能够命令哪个查询运行,而不必重新键入每个查询我想要运行....
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....
推荐答案
我使用了 initialization / 1
test_queries.pl
中的ISO指令可获得您在底部看到的效果。
I've used initialization/1
ISO directive in test_queries.pl
to get the effect you see at bottom.
test_queries.pl
test_queries.pl
test :-
findall(_, (a(X,Y), format('~w ~w~n', [X,Y])), _).
:- initialization([test_inserts]).
:- initialization(test).
test_inserts.pl
test_inserts.pl
a(X,Y) :- append(X,Y,[1,2,3]).
然后使用 - consult-file调用gprolog
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] []
| ?-
这篇关于简单的PROLOG问题:如何测试对您的Prolog数据库的多个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!