4
$\begingroup$

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 ??: enter image description here

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?

$\endgroup$
4
  • 1
    $\begingroup$ ??test calls Information["test"]. Would throwing in a SymbolName as in f0[sym_Symbol] := Information[SymbolName@Unevaluated@sym] do what you want? $\endgroup$
    – user293787
    Aug 16, 2022 at 4:25
  • $\begingroup$ Thanks! that's exactly what I want. It seems that Information[_Symbol] is built from Information[_String], and all these side effects come from convert expressions into strings? @user293787 $\endgroup$
    – Lacia
    Aug 16, 2022 at 4:31
  • $\begingroup$ @user293787 btw you can add an answer and I'll accept it. $\endgroup$
    – Lacia
    Aug 16, 2022 at 4:34
  • $\begingroup$ There are much more knowledgeable people here, perhaps you may want to leave the question open to get more feedback. I have no idea what Information does when given a symbol! $\endgroup$
    – user293787
    Aug 16, 2022 at 4:38

1 Answer 1

8
$\begingroup$

According to the documentation, the special form ??test calls Information["test"].

Therefore, one could modify OPs f0 function by including a SymbolName, in such a way that one passes a string to Information:

f0[sym_Symbol] := Information[SymbolName@Unevaluated@sym]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.