create sql module.
[biolisp.git] / lambda-utils / IO.lisp
blob689f9f63dd85df7196e707ed087a00a85b949696
1 (in-package :lambda-utils)
3 (defparameter *default-external-format* :utf-8)
5 ;;;
6 ;;; Line oriented Processing
7 ;;;
9 (defmacro each-line ((var stream) &body body)
10 "Execute body for each line of stream"
11 `(loop for ,var = (read-line ,stream nil nil)
12 while ,var
13 do ,@body))
15 (defun collect-lines (stream f)
16 "Collect (f line) for the lines of stream"
17 (loop for line = (read-line stream nil nil)
18 while line
19 collect (funcall f line)))
22 ;;;
23 ;;; Read all file
24 ;;;
26 (def-input-fun slurp (stream)
27 (let ((seq (make-string (file-length stream))))
28 (read-sequence seq stream)
29 seq))
32 ;;;
33 ;;; *standard-output* and *standard-input*
34 ;;;
36 (defmacro redirect (file &body body)
37 `(with-open-file (*standard-output* ,file :direction :output :if-exists :supersede)
38 ,@body))