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