Search code examples
prolog

Prolog predicate for declaring one object is larger than the other?


I'm trying to write some simple Prolog code that compares objects and lets us know that one object is larger than the other. For instance,

larger(star, gasgiant).
larger(gasgiant, rockyplanet).
larger(rockyplanet, moon).

The first item listed is larger than the second item listed. This is the relation I was thinking of using to define this:

larger(X, Y) :- X > Y.

Is this the correct way to define this relation?


Solution

  • Is this the correct way to define this relation?

    it can be defined so:

    larger(X,Y):- compare(>, X, Y).
    

    or, simply

    larger(X,Y):- X @> Y.
    

    Have a look at SWI Prolog docs