caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin_jambon@emailuser.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Printing text with holes
Date: Mon, 29 Sep 2003 20:57:36 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.40.0309291951590.9362-100000@pc-bioinfo1> (raw)
In-Reply-To: <3F786FC3.4020807@lexifi.com>

On Mon, 29 Sep 2003, Jean-Marc EBER wrote:

> >
> > This would allow you to do:
> > let _ = stdout <$ "Hello " <$ first_name <$ " " <$ last_name <$ "! It is "
> > <$ (string_of_int time) <$ " o'clock.\n";;
> >
> > Not quite as clean, but close, and it doesn't require p4.
> >
>
> With "old" printf approach, you write something like:
> let _ =
>    printf "Hello %s %s! It is %i o'clock.\n" first_name last_name time
>
> Matter of taste: I prefer the printf version.
>
> More generally, I have found the printf approach (more precisely OCaml's
> Format 'magic' standard module) of incredible power and flexibility, if
>   (and only if :-) ) used consistently through *all* your program. This
> is especially true when you generate "big" documents, where you compose
> recursively many "nice" ways to pretty-print your result(s).

Yes, printf is OK if you don't have to do many substitutions in one time.
This is probably the case most of the time for printing structured output.
But printing human-readable text has a strong constraint: it must fit on
one 2-dimensional page, with a nice appearance and few empty parts.
This is why the programmer likes to have an overview of the
output. Having an overview of the output (its shape) is totally
useless if you need to print tree-like data to be read by a machine.
Just imagine that we want to use a kind of LaTeX or HTML formatting style
from Caml, or find some better solution :-)

In our situation, the problem is that the efforts required for a
modification (let's say the insertion of a new variable) grow with the
size of the output. This is even harder when all your variables have the
same type and if there is more than one screen between the format
specifier and the variable.

Well, I just extracted some code from one of my CGI programs.
Here, the purpose is to print one line of an HTML table, where one column
should appear in bold face (using arrays containing strings "" or "<b>" or
"</b>").
Here is the code:

let print_binary_patch id bb be ranking p =
  let volume1 = p.patch_1.volume in
  let volume2 = p.patch_2.volume in
  let vol_percentage1 = p.patch_1.relative_volume *. 100. in
  let vol_percentage2 = p.patch_2.relative_volume *. 100. in

  let print_option = function
      None -> ()
    | Some s -> << ($s) >> in
  <<
<tr>
  <td>$int{ranking} $matched_tags{p}
  [<a href="$sumo_focus_url?id=$id&index=$int{p.patch_global.patch_number}&quick=false" target=_blank>View</a>]
  [<a href="$sumo_focus_url?id=$id&index=$int{p.patch_global.patch_number}&quick=true" target=_blank>Quick view</a>]</td>
  <td>${bb.(1)}$g{p.patch_global.patch_size}${be.(1)}</td>
  <td>${bb.(2)}$r1{vol_percentage1}% ($r1{volume1})${be.(2)}</td>
  <td>${bb.(3)}$r2{vol_percentage2}% ($r2{volume2})${be.(3)}</td>
  <td>${bb.(4)}$int{p.patch_1.pdb_group_number}${be.(4)}</td>
  <td>${bb.(5)}$int{p.patch_2.pdb_group_number}${be.(5)}</td>
  <td>${bb.(6)}$f3{p.patch_global.patch_sumo_score}${be.(6)}</td>
</tr>
>>

This does not look very beautiful, but for me it is important to have a
compact representation where one line of source code produces not less
than one line of output. This allows to have a global overview of the
output without having to run the program.
The above piece of code has 28 holes... that we must be able to modify at
any time, just because we don't print all the data.



I would like to thank everyone for expressing their opinion on the
subject!


-- Martin

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2003-09-29 18:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-29 13:16 Martin Jambon
2003-09-29 14:10 ` Christian Lindig
2003-09-29 16:25 ` Benjamin Geer
2003-09-29 16:39 ` Brian Hurt
2003-09-29 17:45   ` Jean-Marc EBER
2003-09-29 18:22     ` Brian Hurt
2003-09-29 20:48       ` Pierre Weis
2003-09-29 21:52         ` Richard Jones
2003-09-29 22:07           ` Fred Yankowski
2003-09-29 22:14             ` Daniel M. Albro
2003-09-29 22:19               ` Richard Jones
2003-09-29 22:23             ` Matthieu Sozeau
2003-09-30  3:56             ` Brian Hurt
2003-09-30  4:40         ` Brian Hurt
2003-09-30  6:11           ` David Brown
2003-09-29 18:57     ` Martin Jambon [this message]
2003-09-29 21:25       ` Pierre Weis
2003-09-30 12:52       ` skaller
2003-09-30 17:48         ` Martin Jambon
2003-09-29 18:16   ` Richard Jones
2003-09-29 17:00 ` Pierre Weis
2003-09-29 17:03 ` Karl Zilles
2003-09-29 21:47   ` Pierre Weis
2003-09-30  7:20     ` Jean-Christophe Filliatre

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=Pine.LNX.4.40.0309291951590.9362-100000@pc-bioinfo1 \
    --to=martin_jambon@emailuser.net \
    --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;
as well as URLs for NNTP newsgroup(s).