Problems with comparison in prolog's rules

Skip to first unread message

Magician Artemka

May 25, 2018, 7:42:54 AM5/25/18
to SWI-Prolog

I'm new in Prolog and I create a small base wit "car" statements.

car(ford, mondeo, 125600, 31000).
car(ford, mondeo, 111232, 35000).
car(renault, megane, 82000, 28000).
car(renault, laguna, 102000, 35000).
car(renault, laguna, 82000, 42000).
car(www, pasat, 82000, 42000).
car(renault, aaa, 82000, 428900).

How I can find all cars with >10000 third argument? I try write a rule in consol (!not in the file!) ?- car(Z,X,C > 10000,V). but I get only false (but how? Prolog must print all cars, because all cars are match).

Paulo Moura

May 25, 2018, 7:47:40 AM5/25/18
to Magician Artemka, SWI-Prolog
Prolog is not a functional language. Thus, the argument C > 10000 is not evaluated prior to looking for a matching clause. The query fails as the argument C > 10000 does not unify with any third argument in any of the clauses. Try instead:

?- car(Z,X,C,V), C > 10000.

Here you will be calling the term C > 10000 as a goal instead of using it as a predicate argument.
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> Visit this group at
> For more options, visit

Reply all
Reply to author
0 new messages