In Prolog you can write a ground fact as:
lost(jen).
You can also write a non-ground fact as:
lost(X).
Does this makes any sense? Could you show me a practical/real example where non ground facts are used?
Thanks,
In Prolog you can write a ground fact as:
lost(jen).
You can also write a non-ground fact as:
lost(X).
Does this makes any sense? Could you show me a practical/real example where non ground facts are used?
Thanks,
Well, you can have other things in facts besides atoms, for example you can have lists. Once you've done that, you may want to know about a one-element list, and you can have
oneelement([X]).
Likewise, say you want to compare what is the last element in a list
lastelement([X],X).
lastelement([_|Remainder],X) :- lastelement(Remainder,X).
The very useful member
predicate is defined as
member([X|_],X).
member([_|Remainder],X) :- member(Remainder,X).
Each of these uses a non-ground fact as its base case, by matching a special form that's more specific than just lost(X)
Another case, avoiding lists, is where most cases are "true" and you just want to exclude some few cases that are false. So you deliberately fail thoses cases, then let everything else pass through.
Then you can do, say...
inhabited(antarctica) :- !, fail.
% all the other continents are inhabited
inhabited(_).