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

Bill Wood <william.wood3@comcast.net> writes:

   I'm always inspired in my hacks by Common Lisp's (format...) form, which
   includes a ~{/~} pair containing conversion directives and that consumes
   a list argument.  I don't want to appall you with complexity too soon,
   but when you think about this, consider the possibility that the list is
   a list of lists, each of which contains several items that are to be
   formatted using a a recursively specified (sub) format.  This does
   enhance usability a great deal.  I'm sure that there are people who will
   yelp in protest at this, but I do recommend looking at CL's format as at
   least one point in this design space.
   
I doubt anybody will yelp. Having a printf format for 'a list it
is just natural to permit arbitrary formats for the 'a elements
of the list. Therefore I would suggest something like

Printf.bprintf buf "int pair list: %[(%d, %d) %]" [ 1;2;3;4;5 ]

Here %[ is the list format and everything inbetween %[ and %] is
the format for the list elements (like the  %{ .. %} format). 

It remains to deal with separators that you don't want to print
after the last element. Maybe this could be solved by permitting
flags for %], like 

- flag space "% ]": use space separator, omitted after the last
                    element
- flag comma "%,]": similar for comma
- flag s     "%s]": use next argument as format and interpred
                    this format as separator

A flag that permits a format would also Virgile Prevosto problem:

Virgile Prevosto <virgile.prevosto@m4x.org> writes:

   Le jeu 12 jan 2006 13:55:56 CET, Damien Doligez a écrit:
   > 
   > Yuck.  Isn't this type (formatter -> unit -> unit) isomorphic to string,
   > in the absence of side-effects?  Or do you really need separators that
   > behave differently depending on the state of some reference?
   > 
   
   With Format, yes: you may want to use the pretty-printing features of the
   module, and for instance add a break hint after each element of the list.

Just use 

Format.printf "int pair list: %[(%d, %d)%s]" [ 1;2;3;4;5 ] "@;<2 2>"


BTW, what is the common list solution for printing separators
just between the list elements?

Bye,

Hendrik


  parent reply	other threads:[~2006-01-13  9:32 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 [this message]
2006-01-13 16:28     ` Bill Wood

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=rly81kxylx.fsf@ithif59.inf.tu-dresden.de \
    --to=tews@tcs.inf.tu-dresden.de \
    --cc=caml-list@inria.fr \
    /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