我怎样才能从参数中找到每个仿函数?

时间:2016-06-13 18:05:27

标签: prolog

有了这些事实:

   functor(a,b).
   functor(b,c).
   functor2(a,b).
   functor2(a,c).

我可以问findFunctor(F,a,b).并获取

   F = functor
   F = functor2

感谢您的帮助。

1 个答案:

答案 0 :(得分:4)

这可能适合您使用SWI:

find_functor(Functor, Args):-
 length(Args, Len),
 current_functor(Functor, Len),
 Functor \=':',   % Dismiss :/2 
 Term =.. [Functor|Args],
 predicate_property(Term, number_of_rules(0)),  % It's a fact
 \+ predicate_property(Term, imported_from(_)), % not from a module
 clause(Term, true).

你可以查询

?- find_functor(Functor, [a,b]).
Functor = functor ;
Functor = functor2