I wish to define a function interleaveWithX[statements__]
with behavior such that evaluating, for example,
interleaveWithX[a, b, c, d]
produces the same results as evaluating
a; x; b; x; c; x; d
Getting the arguments interwoven is no problem; something like
interleaveWithX[statements__] := Riffle[List@statements, x]
does the job fine. But assuming that the statements
and x
are already defined, I'm struggling to figure out what combination of SetAttribute
, Hold
, Unevaluated
, ReleaseHold
, Evaluate
, etc. I need to incorporate in my function definition, and where, in order to delay evaluation of the arguments until I've interwoven them into the desired order.