[ create a new paste ] login | about

Link: http://codepad.org/bzmxC71T    [ raw code | fork ]

Scheme, pasted on Mar 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(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)


Create a new paste based on this one


Comments: