Skip to content

Instantly share code, notes, and snippets.

@hisui
Created October 30, 2011 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisui/1325544 to your computer and use it in GitHub Desktop.
Save hisui/1325544 to your computer and use it in GitHub Desktop.
func_style/2
:- op(1200, xfx, ::-).
:- op( 30, fx, ^).
term_expansion(Head ::- Body0, Head :- Body1) :-
func_style(Body0, Body1).
replace_hats(X, X, Vars, Vars, (Z,Z)) :- var(X), !.
replace_hats(**, V, [V|Vars], Vars, (Z,Z)) :- !.
replace_hats(^X, V, Vars1, Vars2, ([P|Preds],Z)) :- !,
replace_hats(X, P, [V|Vars1], Vars2, (Preds,Z)).
replace_hats(Fun1, Fun2, Vars1, Vars2, Preds) :- !,
Fun1 =.. [A|Args1],
merge_hats(Args1, Args2, Vars1, Vars2, Preds),
Fun2 =.. [A|Args2].
merge_hats([], [], Vars, Vars, (Z,Z)) :- !.
merge_hats([Arg1|Args1], [Arg2|Args2], Vars1, Vars3, (Preds1,Z2)) :- !,
replace_hats(Arg1, Arg2, Vars1, Vars2, (Preds1,Z1)),
merge_hats(Args1, Args2, Vars2, Vars3, (Preds2,Z2)),
Z1 = Preds2.
func_style((X1, Y1), (X2, Y2)) :- !,
func_style(X1, X2),
func_style(Y1, Y2).
func_style((X1; Y1), (X2; Y2)) :- !,
func_style(X1, X2),
func_style(Y1, Y2).
list_to_goals([P], P) :- !.
list_to_goals([P|Preds], (Goals, P)) :- list_to_goals(Preds, Goals).
func_style(X1, X3) :-
replace_hats(X1, X2, [], [], (Preds,[])),
list_to_goals([X2|Preds], X3).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment