Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Bill Wood <william.wood3@comcast.net>
To: Hendrik Tews <tews@tcs.inf.tu-dresden.de>
Cc: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Request for comments: Printf list conversion
Date: Fri, 13 Jan 2006 10:28:32 -0600	[thread overview]
Message-ID: <1137169712.19978.32.camel@localhost> (raw)
In-Reply-To: <rly81kxylx.fsf@ithif59.inf.tu-dresden.de>

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




      reply	other threads:[~2006-01-13 16:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-12  9:19 Alessandro Baretta
2006-01-12  9:31 ` [Caml-list] " Jean-Marc EBER
2006-01-12  9:55 ` Jean-Christophe Filliatre
2006-01-12 12:55   ` Damien Doligez
2006-01-12 13:27     ` Virgile Prevosto
2006-01-13  8:47       ` Jean-Christophe Filliatre
2006-01-12 15:50 ` Bill Wood
2006-01-12 17:39   ` Richard Jones
2006-01-12 19:29     ` Bill Wood
2006-01-13  9:31   ` Hendrik Tews
2006-01-13 16:28     ` Bill Wood [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1137169712.19978.32.camel@localhost \
    --to=william.wood3@comcast.net \
    --cc=caml-list@inria.fr \
    --cc=tews@tcs.inf.tu-dresden.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox