Advertisement
logicmoo

%% no_repeats_var(+Var) is det. % % Attribute a varaible to

Nov 15th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 0.63 KB | None | 0 0
  1. %% no_repeats_var(+Var) is det.
  2. %
  3. % Attribute a varaible to never be bound to the same value twice
  4. %
  5. %  ==
  6. %  ?- no_repeats_var(X),member(X,[1,2,3,3,3,1,2,3]).
  7. %  X = 1;
  8. %  X = 2;
  9. %  X = 3;
  10. %  false.
  11. %  ==
  12. no_repeats_var(Var):-must_be(var,Var),put_attr(Var,nr,old_vals([])).
  13. nr:attr_unify_hook(AttValue,VarValue):- AttValue=old_vals(Waz), \+ memberchk_same(VarValue,Waz),nb_setarg(1,AttValue,[VarValue|Waz]).
  14.  
  15. memberchk_same(X, [Y0|Ys]) :- is_list(Ys),!,C=..[v,Y0|Ys],!, arg(_,C,Y), ( X =@= Y ->  (var(X) -> X==Y ; true)),!.
  16. 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