Advertisement
logicmoo

Untitled

Aug 28th, 2014
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. % ===================================================================
  3.  
  4. % ===================================================
  5. %
  6. % call_no_repeats(:Call)
  7. %  (uses newval_or_fail/2)
  8. %
  9. % Like call/1 but ony succeeds on unique free variabes
  10. %
  11. % logicmoo_mud:  ?- call_no_repeats(member(X,[3,1,1,1,3,2])).
  12. % X = 3 ;
  13. % X = 1 ;
  14. % X = 2.
  15. % ===================================================
  16. call_no_repeats(Call):- CONS = cons(car,cdr), term_variables(Call,Vars), call(Call), newval_or_fail(Results,Vars).
  17.  
  18. % ===================================================
  19. %
  20. % call_no_repeats(+Vars,:Call)
  21. %  (uses newval_or_fail/2)
  22. %
  23. % Like call/1 but ony succeeds on unique free variabes
  24. %
  25. % logicmoo_mud:  ?- call_no_repeats( X , member(X-Y,[3-2,1-4,1-5,2-1,])).
  26. % X = 3 ;
  27. % X = 1 ;
  28. % X = 2.
  29. % ===================================================
  30. call_no_repeats(Vars,Call):- CONS = cons(car,cdr),  call(Call), newval_or_fail(Results,Vars).
  31.  
  32.  
  33. % ==========================================================
  34. %    is newval_or_fail/2  - a little term db TO track IF we've seen a term or not
  35. %
  36. % written out FOR understanding  
  37. %
  38. % newval_or_fail(cons(Vars,_),Vars):-!,fail.
  39. % newval_or_fail(CONS,Vars):- CONS = cons(_,cdr), !,nb_setarg(2, CONS, cons(Vars,cdr)).
  40. % newval_or_fail(CONS,Vars):- CONS = cons(car,_), !,nb_setarg(1, CONS, Vars).   % should we even bother TO look here?
  41. % newval_or_fail(cons(_,Nxt),Vars):- newval_or_fail_2(Nxt,Vars).
  42. %
  43. % (combined into one rule FOR immplementing)
  44. % ==========================================================
  45.  
  46. % What may I DO TO simplify OR speed up the below ?
  47. % newval_or_fail(CONS,Vars):- CONS = cons(CAR,CDR), Vars \= CAR, ( CAR=car -> nb_setarg(1, CONS, Vars) ; ( CDR==cdr -> nb_setarg(2, CONS, cons(Vars,cdr)) ; newval_or_fail(CDR,Vars))).
  48.  
  49. %  i skip checking the car each time
  50. newval_or_fail(CONS,Vars):- CONS = cons(CAR,CDR), Vars \= CAR,  ( CDR==cdr ->  nb_setarg(2, CONS, cons(Vars,cdr)) ; newval_or_fail(CDR,Vars)).
  51.  
  52. % what can be done TO speed up?
  53. %  perhapes starting ourt with an array? vv(_,_,_,_,_).
  54. % AND grow with a.. vv(_,_,_,_,vv(_,_,_,_,vv(_,_,_,_,_))) ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement