> My question: which mechanism frees X of the value it was setq-ed?
During function execution, the variables (symbols actually) used as parameters
(in the function definition) are like in an implicit (let):
When executing, the values are bound to the arguments as specified in the
function call, or NIL if the parameter is omitted in the call.
So if the variable (symbol actually) has a value outside of the scope of the
function (during function call!), it regains that value when the scope of the
function is left,
if it has value NIL it regains the value NIL.
So it has not to do with the behaviour of (setq) but how function parameters
I always saw it similar to C, where function parameter variables are like
locally declared variables.