When building other functions I need the HoldAll
version of Information
, and the usual method seems not to work.
Firstly as a comparison, the HoldAll
version of Head
can be constructed as
SetAttributes[{g0,g1},{HoldAll}];
g0[sym_Symbol]:=Head[Unevaluated@sym];
g1[sym_Symbol]:=
Internal`InheritedBlock[{Head},
Unprotect@Head;
SetAttributes[Head,{HoldAll}];
Head@sym
];
test:=(++a;Print@a;a);
and they give the expected results:
a=1;
g0@test
g1@test
(*Symbol*)
(*Symbol*)
However for Information
,
SetAttributes[{f0,f1},{HoldAll}];
f0[sym_Symbol]:=Information[Unevaluated@sym];
f1[sym_Symbol]:=
Internal`InheritedBlock[{Information},
Unprotect@Information;
SetAttributes[Information,{HoldAll}];
Information@sym
];
the test
function will be evaluated inside the HoldAll
version of Information
- f0
and f1
, in contrast to the operator ??
:
It seems that there are some internal functions inside Information
blocking the HoldAll
attributes. Besides this, Information
alse has other side effect.
How to understand this, and build a correct HoldAll
version of Information
?
??test
callsInformation["test"]
. Would throwing in aSymbolName
as inf0[sym_Symbol] := Information[SymbolName@Unevaluated@sym]
do what you want? $\endgroup$Information[_Symbol]
is built fromInformation[_String]
, and all these side effects come from convert expressions into strings? @user293787 $\endgroup$Information
does when given a symbol! $\endgroup$