From 58f600a1bda649cf60568fd6c53784f035899d63 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 2 Jan 2023 21:35:29 +0100 Subject: add sort-by --- mew.scm | 17 ++++++++++++++++- mew.svnwiki | 10 ++++++++-- tests/test.mew | 4 ++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mew.scm b/mew.scm index d0de5e0..70bcff6 100644 --- a/mew.scm +++ b/mew.scm @@ -19,7 +19,7 @@ per pop! prn proj push! puts rand range rep repeat sample scan scan-right sing? search seq set set-at sgn - shuffle shuffle! sort sort! str slurp + shuffle shuffle! sort sort-by sort! str slurp tally-accumulator tbl time while uniq-accumulator unlist until @@ -1361,6 +1361,21 @@ (chicken-sort! xs less?) (error "can only sort! vectors"))))) + (define sort-by + (case-lambda + ((sequence transform) (sort-by sequence transform (sort []) -Sort the list/vector {{}} according to the relation {{less?}} +Sort the list/vector {{}} according to the relation {{}} (by default: {{(sort! []) Sort the vector {{}} destructively according to the relation -{{less?}} (by default: {{?}} (by default: {{(sort-by []) + +Sort the items of the list/vector {{}} by their image under {{f}}, +according to the relation {{}} (by default: {{) v)) (test-error (sort! '(3 2 1)))) + +(test-group "sort-by" + (test '("foobar" "zing" "baz") (sort-by '("foobar" "zing" "baz") + (op - (len _))))) -- cgit 1.4.1