【发布时间】:2013-02-17 00:36:36
【问题描述】:
我正在尝试定义一个内联谓词以将其传递给 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)).
如何去做?
【问题讨论】:
-
对不起,我不明白这一点。你知道lambda吗?
-
不,但在这里使用它似乎有点矫枉过正。不过感谢您的链接。
-
不要使用
(=..)/2来模拟高阶编程。请改用 call/N。它更通用,允许使用library(lambda)
标签: lambda prolog metaprogramming predicate