Given the string “Plot”, you could do
Evaluate[Symbol["Plot"]]::usage
to get the usage string for Plot. But then there are symbols with pre-defined values such as LightRed which evaluates to RGBColor[1, 0.85, 0.85] immediately. You can get around that by Clear’ing LightRed temporarily (already a bit hackish). But you still run into problems with symbols that get a value regardless (after being Clear’ed), e.g. $Line.
So to get from “$Line” to its usage string, I basically do this now:
In[1]:= getSymbol[name_, k_] := If[k <= 1, Symbol[name], getSymbol[name, k - 1]]
In[2]:= getSymbolUsage[symbol_] := symbol::usage
In[3]:= SetAttributes[getSymbolUsage, HoldFirst]
In[4]:= getUsage[name_] := Block[{$IterationLimit = 21}, Quiet[ReleaseHold[getSymbolUsage /@ getSymbol[name, 10]], {$IterationLimit::itlim}]]
In[5]:= getUsage["$Line"]
Out[5]= "$Line is a global variable that specifies the number of the current input line. "
So there is a function getSymbol that does some artificial iteration (because $IterationLimit must be at least 20) in order to stop at the exact point where Symbol has been applied on the string but the own value of the symbol has not been applied yet, so it will return the symbol in a Hold. I can then map a Hold-ing function getSymbolUsage on the Hold expression (containing the symbol) to get the actual usage string (after releasing Hold again).
Is there an easier way to do this? I would assume there is at least some internal functionality to deal with cases like this, but something official would be nicer, of course. I need this to compile a list of all Names[“*”] and their usage strings.
In a broader sense, I sometimes find myself wanting to “do one application of a function without further evaluating its result” (like Symbol in the specific case). Is this $IterationLimit trick the canonical workaround for that, or am I missing something fundamental?