(define-module (here-strings)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 match))
(define (read-here-string c port)
(unless (char=? #\< (read-char port))
(error "Invalid here-string syntax"))
(let ((delimeter (read-line port)))
(let loop ((strings '()))
(match (read-line port 'split)
((line . eol)
(cond ((eof-object? line)
(error "EOF within here-string"))
((string=? line delimeter)
(string-concatenate-reverse (cdr strings)))
((eof-object? eol)
(error "EOF within here-string"))
(else
(loop `(,(string eol) ,line . ,strings)))))))))
(read-hash-extend #\< read-here-string)