Skip to content

Commit 249bf05

Browse files
committed
add fixnum-comparator
1 parent caba7b6 commit 249bf05

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ macros, and comparators:
247247
- `number-comparator` is a default comparator for numbers that is more general
248248
than SRFI 162's `real-comparator`.
249249

250+
- `fixnum-comparator` is a default comparator for fixnums (small integers).
251+
250252
- `(make-sum-comparator <comparators>…)` creates a comparator for the _sum type_
251253
of the types represented by each comparator in `<comparators>`. For example,
252254
`(make-sum-comparator boolean-comparator number-comparator string-comparator)`

comparator.sld

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(export comparator-max comparator-min
2828
comparator-max-in-list comparator-min-in-list
2929
default-comparator boolean-comparator real-comparator
30-
char-comparator char-ci-comparator
30+
fixnum-comparator char-comparator char-ci-comparator
3131
string-comparator string-ci-comparator
3232
pair-comparator list-comparator vector-comparator
3333
eq-comparator eqv-comparator equal-comparator)
@@ -97,6 +97,26 @@
9797
((x) (let ((y 0)) . body))
9898
((x y) . body))))))
9999

100+
(cond-expand
101+
((and (not chicken) (library (srfi 143)))
102+
(import (srfi 143))
103+
(begin
104+
(define fixnum-comparator
105+
(make-comparator fixnum? fx=? fx<? (hash-lambda (x) x)))))
106+
(gerbil
107+
(import (std srfi 143))
108+
(begin
109+
(define fixnum-comparator
110+
(make-comparator fixnum? fx=? fx<? (hash-lambda (x) x)))))
111+
(else
112+
(begin
113+
(define fixnum-comparator
114+
(make-comparator
115+
(λ x (and (number? x) (exact? x) (integer? x)))
116+
=
117+
<
118+
(hash-lambda (x) x))))))
119+
100120
(cond-expand
101121
((and (not chicken) (not gauche) (library (srfi 162)))
102122
(import (srfi 162)))

0 commit comments

Comments
 (0)