I have a knowledge base about movies. My actor and actress predicates look like this:
% actor(M,A,R) -- actor A played role R in movie M
% actress(M,A,R) -- actress A played role R in movie M
I'm trying to count the distinct actors and actresses in my knowledge base. I would simply write:
count(Nr):-
setof(Name,actor(Movie,Name,Role),List1),
setof(Name,actress(Movie,Name,Role),List2),
length(List1,Nr1),
length(List2,Nr2),
Nr is Nr1+Nr2.
It doesn't work, but that way it does:
count(Nr):-
setof(Name,(Movie^Role^actor(Movie,Name,Role)),List1),
setof(Name,(Movie^Role^actress(Movie,Name,Role)),List2),
length(List1,Nr1),
length(List2,Nr2),
Nr is Nr1+Nr2.
So what does that "^"?
Edit: It looks like is something about selecting just once every movie and every role. But I'm still not sure.