-
Notifications
You must be signed in to change notification settings - Fork 4
/
sort.sld
42 lines (39 loc) · 1.7 KB
/
sort.sld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;; Partial implementation of R7RS Large sorting (SRFI 132).
;; Handles Schemes that have SRFI 95 but not 132 (mostly Kawa).
;; Does not include the (start, end) optional parameters of vector functions.
(define-library (schemepunk sort)
(export list-sorted? vector-sorted?
list-sort vector-sort
list-stable-sort vector-stable-sort
list-sort! vector-sort!
list-stable-sort! vector-stable-sort!
list-merge
list-merge!
list-delete-neighbor-dups vector-delete-neighbor-dups
list-delete-neighbor-dups! vector-delete-neighbor-dups!
vector-find-median vector-find-median!
vector-select! vector-separate!)
(cond-expand
((and (not chicken) (or (library (scheme sort)) (library (srfi 132))))
(cond-expand
((library (scheme sort)) (import (scheme sort)))
((library (srfi 132)) (import (srfi 132)))))
(else
(import (scheme base))
(cond-expand
(chicken (import (chicken sort)))
(else (import (srfi 95))))
(begin
(define (list-sorted? < xs) (sorted? xs <))
(define (list-sort < xs) (sort xs <))
(define list-stable-sort list-sort)
(define (list-sort! < xs) (sort! xs <))
(define list-stable-sort! list-sort!)
(define (list-merge < xs ys) (merge xs ys <))
(define (list-merge! < xs ys) (merge! xs ys <))
(define vector-sorted? list-sorted?)
(define vector-sort list-sort)
(define vector-stable-sort list-stable-sort)
(define vector-sort! list-sort!)
(define vector-stable-sort! list-stable-sort!))
(include "polyfills/132-extras.scm"))))