Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% no_repeats_var(+Var) is det.
- %
- % Attribute a varaible to never be bound to the same value twice
- %
- % ==
- % ?- no_repeats_var(X),member(X,[1,2,3,3,3,1,2,3]).
- % X = 1;
- % X = 2;
- % X = 3;
- % false.
- % ==
- no_repeats_var(Var):-must_be(var,Var),put_attr(Var,nr,old_vals([])).
- nr:attr_unify_hook(AttValue,VarValue):- AttValue=old_vals(Waz), \+ memberchk_same(VarValue,Waz),nb_setarg(1,AttValue,[VarValue|Waz]).
- memberchk_same(X, [Y0|Ys]) :- is_list(Ys),!,C=..[v,Y0|Ys],!, arg(_,C,Y), ( X =@= Y -> (var(X) -> X==Y ; true)),!.
- memberchk_same(X, [Y|Ys]) :- ( X =@= Y -> (var(X) -> X==Y ; true) ; (nonvar(Ys),memberchk_same(X, Ys) )).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement