How to find the best matching fact

Remember the warning. (ref)

This document is a reference manual . That means that it documents the system, but it does not explain the basics of the Prolog language and it leaves many details of the syntax, semantics and built-in primitives undefined where SWI-Prolog follows the standards. This manual is intended for people that are familiar with Prolog.

I suspect that you are trying to jump to far ahead. Try taking predicates that you don’t understand such as findall/3 and write test cases (ref) until you clearly understand it.

It took me several months before I was comfortable using such predicates but now they roll off my fingertips like playing music on a piano. :slightly_smiling_face: I still favor setof/3 over findall/3 when starting new code but once the problem starts to congeal and the existentials (^) can be removed, findall/3 is then used.