What's in a ValueList?
It turns out that ValueList
is quite boring after all, it's just used to hold several variables in their unevaluated form and printing them nicely on both InputForm
and OutputForm
(individual entries become separated by double line breaks). The InputForm
behaviour is a difference from HoldForm
, and so is the list-like behaviour, i.e., ValueList[a,b,c]
can be used directly instead of nesting HoldForm@List[a,b,c]
. Otherwise they seem to be identical.
In the link (1) above this is used to pretty print InputForm
like
Format[e_Times,InputForm]:=ValueList[e]/.Power->power/.Times->System`Times;
while for OutputForm
a HoldForm
is sufficient,
Format[e_Times]:=HoldForm[e]/.Power->power/.Times->System`Times;
underlining the fact the only reason not to use HoldForm
in both is that it displays in InputForm
, which is undesirable.
Internally it is used in dumps to store rewrite rules of a symbol like DownValues
, separated into those which can be matched directly (like f[1]
) and those which use patterns, presumably for the purposes of optimisation. One can indeed assign this directly, like
DownValues[f] :=
System`Private`ValueList[System`Private`ValueList[],
System`Private`ValueList[f[u_] :> u^2, f[u_, v_] -> u + v]]
(interestingly, giving the full name an alias like ValueList
results in DownValues rejecting the right hand side on the basis of not being a list), which matches closely the dump contents, albeit the separation is not too important as Mathematica seems to flatten and reorganize this anyway; even a single-level VL works.
Edit: In most cases simply assigning a List
evades evaluation of the right-hand side, too, but an example in (2) shows a case where the contents of a List
is evaluated while assigning to a downvalue. ValueList
provides a possible solution to avoid the side effects of this evaluation.
The differentiation between Rule
s and RuleDelayed
's seems to be lost on first sight,
DownValues[f]
{HoldPattern[f[u_]] :> u^2, HoldPattern[f[u_, v_]] :> u + v}
but is retained for the purposes of Definition
, Save
, etc.
There might be other use cases I am not aware of but this answers all the parts of the question as posed.
In version 10.1.0 under Windows the examples in your reference (3) still work:
System`Private`ValueList[Plus[1, 2^2, 3]] // InputForm
1 + 2^2 + 3
System`Private`ValueList[Plus[1, 2^2, 3]] // OutputForm
1 + 22 + 3
System`Private`ValueList[Plus[1, 2^2, 3]] // FullForm
System`Private`ValueList[Plus[1, Power[2, 2], 3]]