FullForm with context for each symbol?
To not mess with
$ContextPath
you canBlock
it just for that evaluation. e.g.Block[{$ContextPath = {}}, ...]
.But we don't want to do that for the evaluation, input for
FullForm
should be evaluated freely and only the result should be returned with full symbols' names.To achieve that you should know:
$ContextPath
and$Context
affect the typesetting.MakeBoxes
will strip those contexts from an evaluatedFullForm
.
So, to deal with 2
we have to perform MakeBoxes
on our rules (local contexts values) and order that to not be touched by MakeBoxes
anymore (RawBoxes
):
Block[{$ContextPath = {}, $Context = "other`"}
,
RawBoxes @ ToBoxes @ FullForm @ {x, 1}
]
System`List[Global`x,1]
It is very convenient when we want to "toggle a visibility" of specific contexts:
Block[{$ContextPath = {"System`"}, ...
List[Global`x,1]
Based on Kuba's idea, this may also work:
RawBoxes@MakeBoxes[FullForm[p + q]] /.
x_String :> Context[Evaluate@Symbol@x] <> Last@StringSplit[x, "`"] /; NameQ[x]