Re: What "Sort" option of :Values does?
- To: mathgroup at smc.vnet.net
- Subject: [mg120931] Re: What "Sort" option of :Values does?
- From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
- Date: Wed, 17 Aug 2011 05:52:57 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j2cv3a$hfg$1@smc.vnet.net>
On Tue, 16 Aug 2011 06:27:06 +0100, Alexey Popkov <lehin.p at gmail.com>
wrote:
> All the ...Values functions have undocumented option Sort:
>
> In[1]:= Options /@ {OwnValues, DownValues, UpValues, SubValues,
> DefaultValues, FormatValues, NValues}
>
> Out[1]= {{Sort -> True}, {Sort -> True}, {Sort -> True}, {Sort ->
> True}, {Sort -> True}, {Sort -> True}, {Sort -> True}}
>
> What this option does?
>
Sort -> True (the default) sorts *Values into lexicographic order in the
output of these functions, acting as if they were Orderless (which
actually they are not). Sort -> False, on the other hand, keeps them in
the same order that they appear internally, which is to say the order in
which they will be applied (and usually also the order in which they were
defined). A simple example:
In[1] :=
a[2] = 2;
a[1] = 1;
In[3] :=
DownValues[a]
Out[3] =
{HoldPattern[a[1]] :> 1, HoldPattern[a[2]] :> 2}
In[4] :=
DownValues[a, Sort -> False]
Out[4] =
{HoldPattern[a[2]] :> 2, HoldPattern[a[1]] :> 1}
In the case of OwnValues the meaning of this is not readily apparent at
first glance. However, a symbol can actually have multiple OwnValues if
Condition is used, and sorting becomes meaningful in such a case.