Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
In-Place Sort and Reverse List
Sort list elements in ascending order and reverse for descending order.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Collections). Copy the parameterized template or run the self-contained example.
- 1Category: Collections
- 2Attribution: Otter Core Language Spec (D25, D26)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
sort ${targetList}
reverse ${targetList}
scores are
88
42
95
17
.
sort scores
say "Sorted ascending:" scores
if first of scores is not 17
fail with "sort ascending first element mismatch: expected 17"
.
if last of scores is not 95
fail with "sort ascending last element mismatch: expected 95"
.
reverse scores
say "Sorted descending:" scores
if first of scores is not 95
fail with "reverse first element mismatch: expected 95"
.
if last of scores is not 17
fail with "reverse last element mismatch: expected 17"
.
Installation & Usage
otter snippet inspect list-sort-reverse
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.