       Re: Sort problem

• To: mathgroup at smc.vnet.net
• Subject: [mg81739] Re: Sort problem
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Tue, 2 Oct 2007 05:46:59 -0400 (EDT)
• References: <fdqd33\$n6m\$1@smc.vnet.net>

```Donald DuBois wrote:
> Hello,
>
> 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}}
>
>
> What am I doing wrong?
>

This is because "r < a" does not evaluate to False or True.  You don't
need anything special to make Sort[] work in this example:

In:= Sort[{{r, 2}, {a, 3}, {x, 4}}]
Out= {{a, 3}, {r, 2}, {x, 4}}

The correct version of In from your message would be:

In:= Sort[{{r, 2}, {a, 3}, {x, 4}}, OrderedQ[{#1[], #2[]}] & ]
Out= {{a, 3}, {r, 2}, {x, 4}}

--
Szabolcs

```

• Prev by Date: Re: Sort problem
• Next by Date: Re: Number of interval Intersections for a large number of intervals
• Previous by thread: Re: Sort problem
• Next by thread: Re: Sort problem