I can’t come up with a situation where I would need it.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Elegant systems provide
false/0as a declarative synonym for the imperativefail/0. An example where it is useful is when you manually want to force backtracking for side-effects, like:Instead of
false/0, you can also use any goal that fails, for example a bit shorter:Thus,
false/0is not strictly needed but quite nice.EDIT: I sometimes see beginners who want to state for example “my relation does not hold for the empty list”, and then add:
my_relation([]) :- false.to their code. This is not necessary, and not a good example of using
false/0, except for example in failure slices that are programmatically generated. Instead, concentrate on stating the things that hold about your relation. In this case, just leave out the entire clause, and define the relation only for lists that are not empty, i.e., have at least one element:my_relation([L|Ls]) :- etc.or, if you are describing other terms in addition to lists as well, use a constraint like:
my_relation(T) :- dif(T, []), etc.Given only either (or even both) of these two clauses, the query
?- my_relation([]).will automatically fail. It is not necessary to introduce an additional clause which never succeeds for that purpose.