Re: table.sort: invalid order function for sorting

Philippe Verdy <[email protected]> Sun, 26 Apr 2026 13:18:38 +0200
Newsgroups gmane.comp.lang.lua.general
Message-ID <CAGa7JC0DZUOMFTr1a0WVa24itOtws9zTgtRGq-0ULe+qMYtRrw@mail.gmail.com>
If you want stability, suitable for mitlkey sort, or sorts in multiple
passes, and the minimum of swaps for duplicate values, or for NaN values),
using the comparator (a<b) does not work at all, but (a<=b) does.

Lua made the worst decision for its binary comparator used in table.sort!

As a conséquence you always need to rewrite it.

Le ven. 24 avr. 2026, 21:19, 'Martin Eden' via lua-l <[email protected]>
a écrit :

> On 2026-04-24 21:13, Roberto Ierusalimschy wrote:
> >> [...] Have you ever met the case when you need to code effective
> >> sorting in practice?
> > I really don't think this information is relevant to this list. Let us
> > avoid allowing arguments to get too personal. Thanks.
> >
> > -- Roberto
>
> I agree here. Let's consider it as rhetorical question.
>
> But I still want to discuss three-way vs two-way partitioning.
> Current Lua uses two-way as a given fact. I want to evaluate
> alternatives.
>
> -- Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "lua-l" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/lua-l/9f0e3d7f-574f-4825-bb0c-642823cf60d0%40disroot.org
> .
>

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CAGa7JC0DZUOMFTr1a0WVa24itOtws9zTgtRGq-0ULe%2BqMYtRrw%40mail.gmail.com.