An directly runnable example from Stack Overflow implementing simple forward-chaining:
:- module(forward,[ snore/1, sleep/1, collect/2, pull/2 ]). :- use_module(library(chr)). :- chr_constraint snore/1, sleep/1, breathe/1. :- chr_constraint eat/1, live/1, rest/1, collect/2, pull/2. snore(X) ==> breathe(X). snore(X) ==> sleep(X). sleep(X) ==> rest(X). breathe(X) ==> live(X). eat(X) ==> live(X). sleep(X) ==> live(X). live(X) \ live(X) <=> true. % eliminates duplicates collect(Who,L),snore(Who) <=> collect(Who,[snore|L]). collect(Who,L),sleep(Who) <=> collect(Who,[sleep|L]). collect(Who,L),breathe(Who) <=> collect(Who,[breathe|L]). collect(Who,L),eat(Who) <=> collect(Who,[eat|L]). collect(Who,L),live(Who) <=> collect(Who,[live|L]). collect(Who,L),rest(Who) <=> collect(Who,[rest|L]). pull(Who,L) \ collect(Who2,L2) <=> Who = Who2, L = L2.
Now we just need to start SWI-Prolog, and issue these commands:
?- [sleep]. true. ?- sleep(lucy), collect(lucy,[]), pull(Who,L). Who = lucy, L = [rest,live,sleep], pull(lucy,[rest,live,sleep]). ?- snore(john), collect(john,[]), pull(Who,L). Who = john, L = [rest,live,breathe,sleep,snore], pull(john,[rest,live,breathe,sleep,snore]).