Reputation: 23
I'm a high school student studying Prolog and am getting an error on a goal.
I have the following facts:
character(jim).
character(jenny).
character_type(jim, prince).
charcter_type(jenny, princess).
skill(fly).
skill(invisibility).
has_skill(jim, fly).
has_skill(jenny_invisibility).
pet(jim, horse).
pet(jenny, bird).
animal(horse).
animal(bird).
I would like to get all the pets of characters who are princesses. I am trying:
pet(character_type(_, princess), X).
Without successful results. Any help is appreciated.
Upvotes: 1
Views: 498
Reputation: 66
In Prolog, arguments to predicates and functions can only be terms. A term is combinations of variables, constants, and functions. Terms cannot contain predicates.The Predicates are names for functions that are true or false.The functions are something that return non-Boolean values.
The argument passed in pet predicate i.e character_type is a predicate, thus cannot be written as pet(character_type(_, princess), X).
Instead writing the query as character_type(X,princess), pet(X,Y). will give you the desired result. X= jenny Y = bird.
Upvotes: 2
Reputation: 558
you can not use prolog predicate like C-Function
character_type(_, princess)
returns nothing.
I think this is what you intend to do.
character_type(C, princess),pet(C, X).
Upvotes: 1