Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4427 > unrolled thread
| Started by | "Alexey Popkov" <lehin.p@gmail.com> |
|---|---|
| First post | 2011-08-16 05:27 +0000 |
| Last post | 2011-08-17 09:53 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
What "Sort" option of :Values does? "Alexey Popkov" <lehin.p@gmail.com> - 2011-08-16 05:27 +0000
Re: What "Sort" option of :Values does? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-17 09:54 +0000
Re: What "Sort" option of :Values does? "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-17 09:53 +0000
| From | "Alexey Popkov" <lehin.p@gmail.com> |
|---|---|
| Date | 2011-08-16 05:27 +0000 |
| Subject | What "Sort" option of :Values does? |
| Message-ID | <j2cv3a$hfg$1@smc.vnet.net> |
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?
[toc] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-08-17 09:54 +0000 |
| Message-ID | <j2g345$1dn$1@smc.vnet.net> |
| In reply to | #4427 |
On Tue, 16 Aug 2011 13:25:06 +0100, Oleksandr Rasputinov
<oleksandr_rasputinov@hmamail.com> wrote:
> On Tue, 16 Aug 2011 06:27:06 +0100, Alexey Popkov <lehin.p@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.
>
On second thought, the analogy I made above to Orderless is so loose as to
be potentially confusing, so perhaps it is best not to think of it this
way. The point is simply that if *Values were maintained internally as a
sorted list then they would be pattern matched in the same way as the
arguments of Orderless functions are. However, clearly this is not the
case in practice, despite the impression given by the default behaviour of
these functions with Sort -> True.
[toc] | [prev] | [next] | [standalone]
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Date | 2011-08-17 09:53 +0000 |
| Message-ID | <j2g336$1d8$1@smc.vnet.net> |
| In reply to | #4427 |
On Tue, 16 Aug 2011 06:27:06 +0100, Alexey Popkov <lehin.p@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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web