Prolog queries work by pattern matching. The query pattern is called a goal. If there is a fact that matches the goal, then the query succeeds and the listener responds with 'yes. ' If there is no matching fact, then the query fails and the listener responds with 'no.