I'm looking for a way to print a function's arguments, not only unevaluated, but also in the way they were originally typed in.
By way of experimentation, I tried stuff like this:
echo[x___] := ToString[Unevaluated[x]]; SetAttributes[echo, HoldAll];
...but nothing quite worked. For example, with the above function, the expression
Print[TemplateApply[">``<", echo[2^2, "foo", 2 + 2, None]]]
outputs this to the screen:
> 2 Sequence[2 , foo, 2 + 2, None]<
Instead, I want the output to be this:
>2^2, "foo", 2 + 2, None<
IOW, I want the output of
echo to be a string that more closely represents the arguments as they were typed in to Mathematica1.
How can I achieve this?
1 The amount of whitespace between the arguments, however, is not too important. E.g., either
1 ,2,3 or
1, 2, 3 would be OK as the value of
echo[1 ,2,3]. Similarly, preserving fancy typesetting is of secondary importance. The example above shows some of the deviations from perfect faithfulness that I'm most trying to avoid: the
Sequence[...] wrapper, the added second line to accommodate the superscript, and the omission of the double-quotes around strings.