ludic/docs/language/list
Orkuncakilkaya 4aa2012231
Some checks are pending
docs / build-and-deploy (push) Waiting to run
feat(stdlib): sorting toolkit — sort_by/sort_desc_by/sort_with + stable merge sort (#11)
Grow List sorting from a numeric-only insertion sort into a small,
game-friendly toolkit that sorts records and query results by a key or a
full comparator, stably and in O(n log n).

- List.sort_by(s, keyfn)      ascending by a key (draw order, price)
- List.sort_desc_by(s, keyfn) descending (leaderboards)
- List.sort_with(s, cmpfn)    full cmp(a,b)->int comparator (multi-field)

Comparators/keys are passed as named top-level functions rather than
lambdas, so the toolkit ships without waiting on closures (#1).

Engine: a stable bottom-up merge sort. emit_takeright is the single
place stability is decided ("take the right run's head only on a strict
win" -> equal keys keep prior order). List.sort becomes a hybrid:
insertion sort for n<32, merge sort above; both stable, so output is
unchanged. Key functions must return an integer-ish type; record slices
hold pointer elements, so the key/comparator receives the record pointer.

Tests: selfhost/tests/sort.ludic (scalar large-n, sort_by, sort_desc_by,
stability, sort_with). Docs: list-sort_by/desc_by/with + updated
list-sort. All suites green (28 self-host / 46 test / 29 test-tools);
reseeded, C-free bootstrap fixpoint holds.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-30 11:39:26 +03:00
..
_section.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-clear.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-contains.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-first.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-index_of.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-insert.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-last.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-len.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-pop.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-push.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-remove.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-remove_at.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-reverse.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00
list-sort.md feat(stdlib): sorting toolkit — sort_by/sort_desc_by/sort_with + stable merge sort (#11) 2026-08-30 11:39:26 +03:00
list-sort_by.md feat(stdlib): sorting toolkit — sort_by/sort_desc_by/sort_with + stable merge sort (#11) 2026-08-30 11:39:26 +03:00
list-sort_desc_by.md feat(stdlib): sorting toolkit — sort_by/sort_desc_by/sort_with + stable merge sort (#11) 2026-08-30 11:39:26 +03:00
list-sort_with.md feat(stdlib): sorting toolkit — sort_by/sort_desc_by/sort_with + stable merge sort (#11) 2026-08-30 11:39:26 +03:00
list-swap.md feat(stdlib): namespaced standard library (issue #2) 2026-08-30 00:26:19 +03:00