(* Capture Recapture History *)
 
 myCHcc[K_] := Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}]
 
 (* Capture Recapture Probability *)
 
 myindprobCC[CH_]:=Module[{K,ind,fi,li,ans},
 
 
    (* Get $K$ *)
    K = Length[ CH ];
    
    (* First and Last Capture times *)
    fi = First[Position[CH, 1]][[1]];
    li =  Last[Position[CH, 1]][[1]];
    
    (* Get probabilities *)
    
    ans =
  Sum[
   Product[ 
    Subscript[\[Phi],j]
    *
    Subscript[p,j+1]^CH[[j+1]]
    *
    (1-Subscript[p,j+1])^(1-CH[[j+1]]),
    {j,fi,d-1}
   ]*(1-Subscript[\[Phi],d]),
   {d, li, K}
  ];
    
    ans /. Subscript[\[Phi], K]-> 0
]
K = 3
xij = myCHcc[K]
ans = Map[myindprobCC, xij]
Runs perfectly.
There variables involved are
pars =Variables[ans]
However, say by accident, I have done
Subscript[p, 3] = "Dummy"
BEFORE, I define my function "myindprobCC[CH_]", then we have a problem.
Is there a way to "automatically" put ALL "possible" variables, to the Module as local variables, like what i did for "{K,ind,fi,li,ans}".
The problem is that, with the input arguments K_ and C_, the variables vary.
And this is just a simple example.
One way I can think of is to use Table[] to creat them and declare as local variables by hand, but is there a simpler way?
Thanks