forked from okuoku/xitomatl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
library-utils.sls
82 lines (73 loc) · 2.55 KB
/
library-utils.sls
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!r6rs
;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
;; LICENSE from the original collection this file is distributed with.
(library (xitomatl library-utils)
(export
library-name-without-version
library-name-version
library-name?
library-name-symbol?
library-version?
library-name<?
library-version<?)
(import
(rnrs)
(only (xitomatl define) define/?)
(only (xitomatl predicates) list-of? exact-non-negative-integer?
pairwise? symbol<?))
(define/? (library-name-without-version (name library-name?))
(filter symbol? name))
(define/? (library-name-version (name library-name?))
(let ((last (list-ref name (- (length name) 1))))
(and (list? last)
last)))
(define (library-name? x)
(and (pair? x)
(library-name-symbol? (car x))
(let loop ((x (cdr x)))
(if (pair? x)
(if (library-name-symbol? (car x))
(loop (cdr x))
(and (library-version? (car x))
(null? (cdr x))))
(null? x)))))
(define (library-name-symbol? x)
(and (symbol? x)
(positive? (string-length (symbol->string x)))))
(define library-version? (list-of? exact-non-negative-integer?))
(define library-name<?
(pairwise?
(letrec ((name<?
(lambda (x y)
(if (pair? x)
(and (pair? y)
(if (symbol? (car x))
(and (symbol? (car y))
(or (symbol<? (car x) (car y))
(and (symbol=? (car x) (car y))
(name<? (cdr x) (cdr y)))))
(or (symbol? (car y))
(library-version<? (car x) (car y)))))
(pair? y)))))
name<?)
(lambda (x)
(if (library-name? x)
x
(assertion-violation 'library-name<? "not a library name" x)))))
(define library-version<?
(pairwise?
(letrec ((version<?
(lambda (x y)
(if (pair? x)
(and (pair? y)
(or (< (car x) (car y))
(and (= (car x) (car y))
(version<? (cdr x) (cdr y)))))
(pair? y)))))
version<?)
(lambda (x)
(if (library-version? x)
x
(assertion-violation 'library-version<?
"not a library version" x)))))
)