2

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.

false
  • 10,264
  • 13
  • 101
  • 209
Barbi
  • 37
  • 7
  • 4
    It's used in `setof` as an *existential quantifier*. Here's a tutorial which describes it a little: [Prolog: finding all answers](https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_12.html) – lurker Nov 25 '16 at 00:25

0 Answers0