This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/metainterpreters/rules.lgt

49 lines
826 B
Plaintext
Raw Normal View History

:- category(engine).
:- public(prove/1).
:- public(if/1).
:- dynamic(if/1).
:- op(200, fx, if).
:- op(100, xfx, then).
prove(true) :-
!.
prove([]) :-
!.
prove([Cond| Conds]) :-
!,
prove(Cond),
prove(Conds).
prove(Fact) :-
::clause(Fact, true).
prove(Conclusion) :-
::clause(if Conds then Conclusion, true),
prove(Conds).
:- end_category.
:- object(rules,
imports(engine)).
:- public([weather/1, weekday/1, time/1, goto/1]).
:- dynamic([weather/1, weekday/1, time/1, goto/1]).
:- op(200, fx, if).
:- op(100, xfx, then).
if [weather(sunny), weekday(weekend), time(day)] then goto(beach).
if [weather(raining), weekday(weekend), time(night)] then goto(cinema).
if [weekday(workday), time(day)] then goto(work).
weather(raining).
weekday(weekend).
time(night).
:- end_object.