I'm working on SWI-Prolog.
Given the following key-value-pairs list:
List = [pair(key1,1), pair(key2,1), pair(key3,_G1), pair(key4,-_G1), pair(key5,- -_G1)]
Note: in this case the only free variable is G1, but there may be more than 1 free variables.
The value of the pair (Key,Value) may be set to 1.
Otherwise it belongs to the group {Var, -Var, - -Var, - - -Var, ... , - - - ... -Var}
I want to unify Var with the value 1.
Is there any elegant way to do it without parsing the Value?
I tried the numbervars predicate but it will only write letters to the variables.
I also got a working predicate that solves it, but I'm looking for a more elegant way.
fixFreeVars([]).
fixFreeVars([kvp(_,X)|KVPs]) :-
fixFreeVar(X),!,
fixFreeVars(KVPs).
fixFreeVar(X) :- var(X), X = 1.
fixFreeVar(-X) :- fixFreeVar(X).
fixFreeVar(X) :- nonvar(X).
Any suggestions?
-
) as operator but no other operators? This looks odd to me. – false