-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.scm
30 lines (26 loc) · 865 Bytes
/
util.scm
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 slurp-loop
(lambda (line result)
(if (eof-object? line)
result
(slurp-loop (read-line) (string-append result line (string #\newline))))))
(define slurp
(lambda (path)
(with-input-from-file
path
(lambda ()
(slurp-loop (read-line) "")))))
(define string-starts-with?
(lambda (str prefix)
(and (>= (string-length str) (string-length prefix))
(string=? (string-copy str 0 (string-length prefix)) prefix))))
(define number-of-line->number
(lambda (str)
(letrec
((looper
(lambda (chars result)
(if (and (not (null? chars))
(char-whitespace? (car chars)))
(begin
(string->number result))
(looper (cdr chars) (string-append (string (car chars)) result ))))))
(looper (reverse (string->list str)) ""))))