Re: how to get predicats from facts?
- From: Martin Riener <martin.riener@xxxxxxxxx>
- Date: Mon, 24 Dec 2007 11:19:26 +0100
corps wrote:
suppose we have
person(tom).
person(mike).
cat(tom).
cat(lisa).
how can we make a function
get_predicates(tom). to get [cat,person]?
get_predicates(Name,L) :-
findall(X, X(Name), L).
doesn't work.
get_predicates(Name,L) :-
findall(X, call(X, Name), L).
doesn't work either.
Thanks for any reply.
take a look at =.. and functor/3 :)
unarypredicate_solutions(Name,S) :-
Pred =.. [Name,A],
findall(A, Pred, S).
if you take into account predicates with arity >= 2 it looks something like:
predicate_solutions(Name/Arity,S) :-
length(L,Arity),
append([Name],L,P),
Pred =.. P,
findall(L, Pred, S).
Please take into account that this is what came to my mind first - there
is no check, if the predcate exists and it is certainly not the most
elegant solution.
hth, Martin
.
- Follow-Ups:
- Re: how to get predicats from facts?
- From: Jan Wielemaker
- Re: how to get predicats from facts?
- References:
- how to get predicats from facts?
- From: corps
- how to get predicats from facts?
- Prev by Date: how to get predicats from facts?
- Next by Date: Re: how to get predicats from facts?
- Previous by thread: how to get predicats from facts?
- Next by thread: Re: how to get predicats from facts?
- Index(es):