Mark Wooding <mdw@distorted.org.uk> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > #:with-output-to-file ; Save typing in the most common output case.
|
| I have a SAFELY-WRITING macro which opens a stream onto a fresh file
| (using :IF-EXISTS NIL), and either renames the file into place on
| successful completion or deletes it on failure. It's based on a more
| complicated infrastructure of stuff which handles multiple files and
| other operations such as file deletion.
+---------------
Mine does the opposite extreme of "safety": it unconditionally
writes over the file whether or not it exists [unless you supply
a different explicit :IF-EXISTS]:
(defmacro with-output-to-file ((stream filename
&key (direction :output) (if-exists :supersede)
&rest rest &allow-other-keys)
&body body)
`(with-open-file (,stream ,filename
:direction ,direction :if-exists ,if-exists ,@rest)
,@body))
+---------------
| > #:stringify ; Coerce items in atom/list/tree to strings.
|
| I have a function with this name, but it's simpler:
| (defun stringify (thing)
| (typecase thing
| (string thing)
| (symbol (symbol-name thing))
| (t (princ-to-string thing))))
+---------------
Mine translates NIL to "", rather than "NIL", mainly because
of what I tend to use it for [building web pages & other docs].
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607