aLu
aLu

Reputation: 47

Assert numeric predicates in Prolog

Is there a possibility in Prolog to assert facts that represent a number? For example, I would like to use a predicate distance/2 and assert facts like distance(town1, city2) = 1200.

Upvotes: 2

Views: 158

Answers (1)

Paulo Moura
Paulo Moura

Reputation: 18663

The distance(town1, city2) = 1200 term is syntactic sugar for the term '='(distance(town1, city2), 1200) as (=)/2 is a standard Prolog infix operator. (=)/2 is also the standard unification built-in predicate. In most Prolog systems, built-in predicates cannot be redefined by the user. Thus, you cannot assert clauses for them as that would amount to redefine the predicate. Carlo's suggestion of using a distance/3 predicate is likely the best solution.

Upvotes: 3

Related Questions