Inspired by this question, if I have a list
{a, p, b, q, c}
where p
and q
are binary operators, such as Plus
and Times
, how would I construct the expression
a ~ p ~ b ~ q ~ c
and execute it?
Obviously, the solution proposed in the other question of constructing it via strings is the most straightforward approach, but I would like to know if the infix formulation, above, is doable without resorting to string manipulation.
Hold[{a, Plus, b, Times, c}] //. {PatternSequence[a_, p_, b_, c___]} :> {p[a, b], c}
work? $\endgroup$