-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlist-count.rkt
More file actions
53 lines (48 loc) · 1.08 KB
/
Copy pathlist-count.rkt
File metadata and controls
53 lines (48 loc) · 1.08 KB
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
43
44
45
46
47
48
49
50
51
52
53
#lang racket/base
(require racket/contract/base
racket/match
racket/list)
(define list/count
(or/c exact-nonnegative-integer? (listof bytes?)))
(define lc->number
(match-lambda
[(? number? x)
x]
[(? list? x)
(length x)]))
(define lc->list
(match-lambda
[(? number? x)
empty]
[(? list? x)
x]))
(define lc-zero?
(match-lambda
[(? number? x)
(zero? x)]
[(? list? x)
(eq? empty x)]))
(define (-lc+ x y)
(cond
[(number? x)
(+ x (lc->number y))]
[(number? y)
(+ (lc->number x) y)]
[else
(append x y)]))
(define (lc+ x . args)
(cond [(null? args) x]
[else (foldr -lc+ x args)]))
(define (lc-sort l)
(cond
[(number? l)
l]
[else
(sort (remove-duplicates l) bytes<?)]))
(provide/contract
[list/count contract?]
[lc+ ((list/count) #:rest (listof list/count) . ->* . list/count)]
[lc->number (list/count . -> . exact-nonnegative-integer?)]
[lc-sort (list/count . -> . list/count)]
[lc->list (list/count . -> . (listof bytes?))]
[lc-zero? (list/count . -> . boolean?)])