I have a few questions regarding rules, terms, and sorts (datatypes):
(1) I occasionally see the error “predicate not defined”. This happens with rules like scared(P) :- no_escape(P), faces_conflict(P), is_weaker(P)
when I’ve previously written is_weaker(john)
, faces_conflict(john)
but not written anything about no_escape
.
-
(1A) Does SWI-Prolog (or all Prologs?) require seeing a term on its own before it is used in a rule? There is no default to false or undetermined?
-
(1B) If I must provide a term on its own before using it in a rule, does it need to be grounded? Is there a way to provide something like a function signature in imperative programming where I define the arity, datatypes, and return type – without grounding.
(2) What is the correct way to accomplish disjunction/or in the body of a rule? Do I just write multiple versions of the same rule and pattern matching selects the ones that fire:
fire :- enemy_in_range.
fire :- bored.
(3) I’ve read that programs with datatypes in Prolog are called “sorted” or “many-sorted”. I don’t mean datatypes for exchanging data.
- (3A) How is this accomplished in SWI-Prolog? For example, if I want to specify
can_run(P)
but only ifperson(P)
. I can do this in a rule using an “and”(,
) but am looking for something likecan_run(P::person)
. - (3B) Does using sorts improve performance by filtering down the search space?