Sunday, 3 February 2019

How to create facts in prolog?


You can create facts a prolog file and load them using consult function.

For example,
animals.pl
bigger(elephant, tiger).
bigger(tiger, rabbit).
bigger(rabbit, sparrow).
bigger(sparrow, ant).

1 ?- consult(animals).
true.

2 ?- bigger(tiger, rabbit).
true.

3 ?- bigger(dragon, bluewhale).
false.



You can also use assert function to define facts in prolog terminal.
1 ?- assert(bigger(elephant, rabbit)).
true.

2 ?- assert(bigger(rabbit, ant)).
true.

3 ?- bigger(elephant, rabbit).
true.

assert(bigger(elephant, rabbit)).
assert(bigger(rabbit, ant)).
Above two statements define the facts.

bigger(elephant, rabbit).
Above statement asks prolog, is elephant bigger than rabbit?



Previous                                                 Next                                                 Home

No comments:

Post a Comment