caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: "Undisclosed.Recipients": ;
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Pervasives or Printf module ?
Date: Sun, 22 Jan 2006 15:34:04 +0000	[thread overview]
Message-ID: <200601221534.04835.jon@ffconsultancy.com> (raw)
In-Reply-To: <43D3A058.6030305@yahoo.fr>

On Sunday 22 January 2006 15:10, sejourne_kevin wrote:
> As the usage of:
>            Printf.sprintf "_%d" x
> and
>            "_"^(string_of_int x)

That can be written without parentheses and the style guide advises the use of 
spaces around operators (i.e. "^"):

  "_" ^ string_of_int x

> is the same, what is the better solution?
>
> Do you have an opinion for the one or the second?

I tend to avoid Printf and stick with Pervasives where possible.

You can do some nice things with printf, like exploit currying:

# List.iter (Printf.printf "%d ") [1;2;3];;
1 2 3 - : unit = ()

but it is easy to trip up:

# List.iter (Printf.printf " %d") [1;2;3];;
 123- : unit = ()

Note: the former prints a space after every integer whereas the latter prints 
only a single space at the beginning. To get the latter to act as the former 
does, you must beta expand (I think that is the correct technical term) to 
postpone the computation of printf " ":

# List.iter (fun n -> Printf.printf " %d" n) [1;2;3];;
 1 2 3- : unit = ()

If efficiency is a concern then I would expect printf to be faster because it 
should avoid string concatenation. I haven't tested that though...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


  reply	other threads:[~2006-01-22 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-22 15:10 sejourne_kevin
2006-01-22 15:34 ` Jon Harrop [this message]
2006-01-22 16:27   ` [Caml-list] " Anil Madhavapeddy
2006-01-22 16:42     ` sejourne_kevin
2006-01-22 16:46   ` Vincenzo Ciancia
2006-01-23  9:18     ` [Caml-list] " Remi Vanicat

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=200601221534.04835.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --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).