Skip to main content
Post Undeleted by Kuba
added 117 characters in body
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

ThisI though it is quite nice and general approachuntill I had to add reparse function :)

SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; reparse = ToExpression @* FrontEndExecute @* FrontEnd`ReparseBoxStructurePacket @* ToBoxes y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] //reparse 
 Hold[{1, y, 1 + 2, 2, y, 1 + 2, 3}] 

This is quite nice and general approach:

SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] 
 Hold[{1, y, 1 + 2, 2, y, 1 + 2, 3}] 

I though it is nice untill I had to add reparse function :)

SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; reparse = ToExpression @* FrontEndExecute @* FrontEnd`ReparseBoxStructurePacket @* ToBoxes y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] //reparse 
 Hold[{1, y, 1 + 2, 2, y, 1 + 2, 3}] 
Post Deleted by Kuba
Source Link
Kuba
  • 138.9k
  • 13
  • 297
  • 803

This is quite nice and general approach:

SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] 
 Hold[{1, y, 1 + 2, 2, y, 1 + 2, 3}]