-
Notifications
You must be signed in to change notification settings - Fork 0
/
sexp-file-io.scm
30 lines (27 loc) · 918 Bytes
/
sexp-file-io.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 (write-sexps filename sexps)
(call-with-port
(open-output-file filename)
(lambda (op)
(let loop ([sexps sexps])
(if (null? sexps)
(void)
(begin (pretty-print (car sexps) op) (loop (cdr sexps))))))))
(define (read-sexps filename)
(call-with-port
(open-input-file filename)
(lambda (ip)
(let loop ([sexps '()])
(let ((sexp (read ip)))
(if (eof-object? sexp)
(reverse sexps)
(loop (cons sexp sexps))))))))
(define (write-bytevector-into-file loc vs)
(call-with-port
(open-file-output-port loc)
(lambda (op)
(put-bytevector-some op (u8-list->bytevector (vector->list vs))))))
(define (read-bytevector-from-file loc)
(call-with-port
(open-file-input-port loc)
(lambda (ip)
(list->vector (bytevector->u8-list (get-bytevector-some ip))))))