Browse thread
Request for comments: Printf list conversion
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Bill Wood <william.wood3@c...> |
| Subject: | Re: [Caml-list] Request for comments: Printf list conversion |
On Fri, 2006-01-13 at 10:31 +0100, Hendrik Tews wrote:
. . .
> I doubt anybody will yelp. Having a printf format for 'a list it
That would be nice :-). However, even some lispers have complained
(with some justification) that writing format forms was like writing
TECO macros, or minimalistic Perl.
> BTW, what is the common list solution for printing separators
> just between the list elements?
There is no special provision for separators that I know of. I always
just took the cheap way out, first formatting the head of the list and
then formatting the tail with a list format that prints the separator
and then the next item. A sample transcript in CLISP is*
(let ((xs '(0 1 2 3)))
(format t "~%>~s~{, ~s~}<~%" (first xs) (rest xs)))
>0, 1, 2, 3<
This is facilitated by the conditional format directive, allowing
different formats depending on whether the list argument is empty or
non-empty.
-- Bill Wood
* The syntax of the CL format form is
(format <target> <format string> <arg> ...)
where <target> specifies returning a string, printing to stdout, or
printing to a stream, <format string> is a string containing format
directives together with ordinary characters, and the remaining args
are the objects being formatted out.
Format directives are prefixed with "~"; the directive "~%" produces a
newline and the directive "~s" formats any lisp s-expression, like a
Haskell "show x".
-- wtw