Skip to content

Instantly share code, notes, and snippets.

@jarble
Last active November 8, 2018 23:07
Show Gist options
  • Select an option

  • Save jarble/be75ad57bbbbe6578f5d435dc9ed221a to your computer and use it in GitHub Desktop.

Select an option

Save jarble/be75ad57bbbbe6578f5d435dc9ed221a to your computer and use it in GitHub Desktop.
This is an attempt to write a meta-interpreter for Constraint Handling Rules.
:- initialization(main).
:- set_prolog_flag('double_quotes','chars').
:- use_module(library(chr)).
:- chr_constraint is_true/1.
is_true(X) \ is_true(X) <=> true.
is_true(X ==> Y),is_true(X1) ==> copy_term((X -> Y),(X2 -> Y1)),(X2=X1,(is_true(X1)->is_true(Y1));X2\=X1),writeln(Y).
is_true((X;Y)) ==> is_true(X);is_true(Y).
is_true((X,Y)) ==> is_true(X),is_true(Y).
is_true(is_true(X)) ==> is_true(X).
is_true(X),is_true(\+X) ==> false.
main :-
is_true(is_person(A)==>is_mammal(A)),
is_true(is_mammal(A)==>is_animal(A)),
is_true(is_person(sue)),is_true(is_person(bob)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment