I've got a weird problem here....
So I have a function that takes blocks of codes and them uses Map on them and passes them around and then selects and returns the one that is needed.
A simplified dummy of it is given below:
In:
SetAttributes[func, HoldAll];
func[exprs__] := Which[Evaluate[Sequence @@ (# & /@ Inactivate[{exprs}])]];
Now, using it:
(* say every even-numbered index argument is a code block: *)
In: func[a, 1, b, x = 1; 2, c, 0]
Out: Which[a, 1, b, x = 1; 2, c, 0]
In: Simplify[%, a == False && b == True]
Out: x = 1; 2
(* along the line it gets activated *)
In: Activate[%]
Out: 2
In: x
Out: 1
Ok, now what if x has been set: x = 9 before the code immediately block-quoted above.
In: func[a, 1, b, x = 1; 2, c, 0]
Out: Which[a, 1, b, 9 = 1; 2, c, 0]
So by the time it gets to Activate, we have a: Set::setraw error
The Inactivate and SetAttributes[_, HoldAll] makes sure the x does not immediately gets aggressively replaced by 9, but somewhere along the line, the Map, Sequence and Evaluate aggressively replaces it. I haven't tried SetAttribute-ing them all for HoldAll, but is less intrusive way (from the point-of-view of these built-in functions) of holding these replacements??
In reality, my func immediately calls Activate, looking more like this very simplified dummy:
In: func[exprs__] := Activate[Which[Evaluate[Sequence @@ (# & /@ Inactivate[{exprs}])]];
But the step-by-step code further above that I've shown re-produces what I've been getting. Also with immediately above:
In: func[a, 1, b, x = 1; 2, c, 0]
Out: Which[a, 1, b, 9 = 1; 2, c, 0]
In: Simplify[%, a == False && b == True]
Out: 2
and the 9 = 1;
magically doesn't seem to happen (neither x is 1 nor a setraw error pops up), so I decided it was a poor example to state the case. But the question is the same, is there a less intrusive way?