如何收集规则

时间:2015-03-15 21:12:49

标签: prolog rule

我想要做的是返回我可以为应用获取的所有变量。应用程序具有可扩展的变量,我可以使用其他一些变量扩展它们,以及不可扩展的变量。

我的目标是查询getvariables_for_app(web1),并获取应用程序的可扩展和不可扩展变量的简单平面(或复杂)列表。

% Not extendable variables
vartype(geocoordinate(latitude, longitude)).

% Extendable variables
vartype(street, location).
vartype(city, location).
vartype(housenumber, location).
vartype(postal_code, location).

% Extensions
extension(location, geocoordinate(latitude, longitude)).

% Variables per app
app(web1, street).
app(web1, city).
app(web1, housenumber).
app(web1, postal_code).

但是,我不确定如何制定此规则以获取我需要的列表。

getvariables_for_app(X) :- app(X, Y) ....

更新(到目前为止我的回报很好,我一次只得到1):

getvariables_for_app(X,R) :- app(X, Y), vartype(Y, Z), extension(Z, R). 

预期产出:

% order does not matter:
[geocoordinate(latitude, longitude), city, housenumber, postal_code, street]

0 个答案:

没有答案