Consider
e1 = Hold[a = x + x; b = y + y + y];
e2 = Hold[c = a + a + b + b + b; c^2];
How can I obtain the following?
e12 = Hold[a = x + x; b = y + y + y; c = a + a + b + b + b; c^2]
For example,
e1 ~Join~ e2
does not work since it gives one "," sign in the middle. another attempt
With[{e1temp = e1, e2temp = e2}, Hold[e1temp; e2temp]]
gives nested Hold
calls that at the end do not want to evaluate (and are hard to get rid off):
Hold[Hold[a = x + x; b = y + y + y]; Hold[c = a + a + b + b + b; c^2]]]
I am amazed that such a simple thing is causing me so much pain. :)
Edit
My current solution.
merge[Hold[expr1_], Hold[expr2_]] := Hold[expr1; expr2]
merge[e1, e2]
Hold[(a = x + x; b = y + y + y); (c = a + a + b + b + b; c^2)]
Join
. It should bemerge[Hold[CompoundExpression[expr1__]], Hold[CompoundExpression[expr2__]]] := Hold[CompoundExpression[expr1, expr2]]
. $\endgroup$e12 = Thread[Join[e1, e2]]
givesHold[a = x + x; b = y + y + y, c = a + a + b + b + b; c^2]
However, as Szabolcs pointed out in a comment to the answer I had posted, it puts it as two elements in theHold
with the comma in between. I realized that this was the same as what zorank had meant with the~Join~
command, so I have deleted it as an answer and moved it here to a comment. $\endgroup$