Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % ===================================================================
- % ===================================================
- %
- % call_no_repeats(:Call)
- % (uses newval_or_fail/2)
- %
- % Like call/1 but ony succeeds on unique free variabes
- %
- % logicmoo_mud: ?- call_no_repeats(member(X,[3,1,1,1,3,2])).
- % X = 3 ;
- % X = 1 ;
- % X = 2.
- % ===================================================
- call_no_repeats(Call):- CONS = cons(car,cdr), term_variables(Call,Vars), call(Call), newval_or_fail(Results,Vars).
- % ===================================================
- %
- % call_no_repeats(+Vars,:Call)
- % (uses newval_or_fail/2)
- %
- % Like call/1 but ony succeeds on unique free variabes
- %
- % logicmoo_mud: ?- call_no_repeats( X , member(X-Y,[3-2,1-4,1-5,2-1,])).
- % X = 3 ;
- % X = 1 ;
- % X = 2.
- % ===================================================
- call_no_repeats(Vars,Call):- CONS = cons(car,cdr), call(Call), newval_or_fail(Results,Vars).
- % ==========================================================
- % is newval_or_fail/2 - a little term db TO track IF we've seen a term or not
- %
- % written out FOR understanding
- %
- % newval_or_fail(cons(Vars,_),Vars):-!,fail.
- % newval_or_fail(CONS,Vars):- CONS = cons(_,cdr), !,nb_setarg(2, CONS, cons(Vars,cdr)).
- % newval_or_fail(CONS,Vars):- CONS = cons(car,_), !,nb_setarg(1, CONS, Vars). % should we even bother TO look here?
- % newval_or_fail(cons(_,Nxt),Vars):- newval_or_fail_2(Nxt,Vars).
- %
- % (combined into one rule FOR immplementing)
- % ==========================================================
- % What may I DO TO simplify OR speed up the below ?
- % 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))).
- % i skip checking the car each time
- 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)).
- % what can be done TO speed up?
- % perhapes starting ourt with an array? vv(_,_,_,_,_).
- % AND grow with a.. vv(_,_,_,_,vv(_,_,_,_,vv(_,_,_,_,_))) ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement