我正在尝试定义一个谓词内联以将其传递给 Prolog 中的另一个谓词。
% Test if a "product" of graphs G1 and G2 has a "mini-loop" starting from Q
test_property_combined(G1,G2,Q):-
(g12(Q1,Q2) :- combine(G1,G2,Q1,Q2)),
some_property(g12,Q).
(上面的语法显然是错误的。)
稍后g12
将被调用call
% Test if a graph G has a "mini-loop" starting from Q
some_property(G,Q):-
Goal1 =.. [G,Q,C],
Goal2 =.. [G,C,Q],
call(Goal1),
call(Goal2).
问题仍然存在,因为我想测试some_property
某种先前定义的谓词的聚合。
% Create a "product" of graphs G1 and G2
combine(G1,G2,(Q1,Q2),(Q3,Q4)):-
Goal1 =.. [G1,Q1,Q3],
Goal2 =.. [G2,Q2,Q4],
call(Goal1),
call(Goal2).
上述谓词和测试查询示例:
% g1 and g2 are graphs
g1(a,b).
g1(b,a).
g2(c,d).
g2(d,c).
?- test_property_combined(g1,g2,(a,c)).
怎么做呢?