This is the mail archive of the
guile@cygnus.com
mailing list for the Guile project.
here-strings a la SCSH
- To: guile@cygnus.com
- Subject: here-strings a la SCSH
- From: Michael Livshin <mike@olan.com>
- Date: 25 Jun 1999 12:14:00 +0200
- Organization: who? me?
- Reply-to: Michael Livshin <mike@olan.com>
yes, I know it's in guile-scsh. to my defence, I wrote it, like, ten
minutes before it occured to me to check guile-scsh ;).
so here it is, maybe you will find it useful anyway.
benefits: you don't need guile-scsh for it, it's better optimized for
Guile, it's in public domain. enjoy.
;;; here-strings.scm --- SCSH-like here-strings
;; -*- Scheme -*-
; Copyright (C) 1999 Michael Livshin
; This code is in public domain, do with it what you want.
(define-module (util here-strings))
(define (read-here-string c port)
(define (assert-non-eof c)
(if (eof-object? c)
(error 'eof "end of file in here-string")))
(with-input-from-port port
(lambda ()
(let ((d (read-char)))
(if (char=? d #\<)
(let ((delim (read-line)))
(if (string=? "" delim)
(error 'empty-delimiter "empty here-string delimiter line"))
(with-output-to-string
(lambda ()
(let loop ((l (read-line)) (newline ""))
(assert-non-eof l)
(or (string=? l delim)
(begin
(display newline)
(display l)
(loop (read-line) #\newline)))))))
(read-delimited (make-string 1 d)))))))
(read-hash-extend #\< read-here-string)
;;; here-strings.scm ends here