let get_onlyvar (no_vars : int list) (ls : term list) : int option =
(* foundvar indicates, if we already found a variable and which. It does not
* matter what is the int value, if the bool value is false. *)
let rec get_onlyvar_rec (foundvar : bool * int) = function
| Var(n)::tail ->
if List.mem n no_vars then
(* treat Var(n) like an atom *)
get_onlyvar_rec foundvar tail
else
if fst foundvar then
(* at least two variables not in no_vars found *)
None
else
get_onlyvar_rec (true,n) tail
| _::tail -> get_onlyvar_rec foundvar tail
| [] ->
if fst foundvar then
(* only one variable not in no_vars found *)
Some (snd foundvar)
else
(* no variables not in no_vars found *)
raise No_Solution
in
if ls = [] then
None
else
get_onlyvar_rec (false,-1) ls