-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.spec
30 lines (25 loc) · 842 Bytes
/
strings.spec
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
(define (Itoa i) (sprintf "%d" i))
// This is only to be used if the type of the value is unknown, as a more
// specific conversion is always preferred.
(define (Str value) (sprintf "%v" value))
// XXX This will be deprecated
// func: Run on every item the itemList, one at a time
(define (ListToStr itemList func delimiter)
(if (= (len itemList) 0)
// XXX This should be an error
""
(if (= (len itemList) 1)
(func (nth 0 itemList))
(reduce
(lambda (x y)
(sprintf "%s%s%s" x delimiter y))
(map func itemList)))))
(define (Concat x y) (sprintf "%v%v" x y))
(define (Join lst delim)
(if (= (len lst) 0)
""
(if (= (len lst) 1)
(car lst)
(reduce (lambda (x y) (+ x delim y)) lst))))
(define (Range prefix n)
(map (lambda (i) (sprintf "%s-%d" prefix i)) (range n)))