       Re: Sort problem

• To: mathgroup at smc.vnet.net
• Subject: [mg81722] Re: Sort problem
• From: mcmcclur at unca.edu
• Date: Tue, 2 Oct 2007 05:38:13 -0400 (EDT)
• References: <fdqd33\$n6m\$1@smc.vnet.net>

```On Oct 1, 5:02 am, Donald DuBois <don... at comcast.net> wrote:
> This Sort works
> In:= Sort[{r, a, x}]
> Out= {a, r, x}
>
> but this one doesn't:
> In:= Sort[{{r, 2}, {a, 3}, {x, 4}}, #1[] < #2[] &]
> Out= {{r, 2}, {a, 3}, {x, 4}}

According to the documentation, the default ordering function
for Sort is OrderedQ[{#1,#2}]& (as opposed to Less, which you use).
Thus, to emulate this behavior with the restriction to the first
element, you could use:
Sort[{{r, 2}, {a, 3}, {x, 4}},
OrderedQ[{#1[], #2[]}] &]

Conversely, you could force the more confusing behavior in the
first example by switching the input to
Sort[{r, a, x}, #1 < #2 &]

I suppose the reason is that Less compares numerical quantities,
while OrderedQ is more general.

Mark

```

• Prev by Date: Re: Other bug in ContourPlot
• Next by Date: Re: Equivalent functionality to colorbar in Mathematica?
• Previous by thread: Re: Sort problem
• Next by thread: Re: Sort problem