FullForm
strips the context for any symbol that can be found on the Append[$ContextPath, $Context]
: FullForm[System`List]
is displayed List
, but I would like to get System`List
for debugging and learning purposes.
I tried $ContextPath = {}
but then the whole front-end stops working [1].
Is there another way besides
Hold[...] /. x_Symbol :> (Context@x <> SymbolName@Unevaluated@x)
Is there any case where this would not work?
[1] I find it strange that the internal code of the FrontEnd relies on the "usability features" $Context
and $ContextPath
. Why doesn't it use the full symbol names for any code it uses (or produces)? IMO $ContextPath = {}
should hurt you (having to type the full name of any symbols not in $Context
), but not the system. If it really needs System`
to operate properly, it should not allow setting $ContextPath = {}
just like it is not allowed to set $Context
to something invalid.
[2] Note that Context
has HoldFirst
while SymbolName
doesn't, hence the Unevaluated
.
Answer
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]
Comments
Post a Comment