I would like to understand the following module subtlety. Consider two seemingly equivalent instances
Module[{temp}, Sequence[x, x]]
(Module::argrx: Module called with 3 arguments; 2 arguments are expected.)
and
Module[{temp}, temp = Sequence[x, x]]
(Sequence[x, x])
While the first complains about bad syntax (three arguments instead of expected two), the second performs as expected. Why the difference?
Module[{temp}, Sequence[x, x]]
becomesModule[{temp}, x, x]
hence the error. ButModule[{temp}, temp = Sequence[x, x]]
remains as is.Sequence[x, x]
should becomex,x
in function calls. I admit I do not know why it unwrapped in the first usage you had instead of remainingSequence[x, x]
but this is what Mathematica did. You can see the automatic unwrapping if you typefoo[Sequence[x, x]]
then becomesfoo[x,x]
$\endgroup$Module
has attributeHoldAll
but notSequenceHold
whereasSet
has attributeSequenceHold
. $\endgroup$