Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Anil Madhavapeddy <anil@recoil.org>
To: Jon Harrop <jon@ffconsultancy.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Pervasives or Printf module ?
Date: Sun, 22 Jan 2006 16:27:45 +0000	[thread overview]
Message-ID: <20060122162745.GA20731@fork.recoil.org> (raw)
In-Reply-To: <200601221534.04835.jon@ffconsultancy.com>

On Sun, Jan 22, 2006 at 03:34:04PM +0000, Jon Harrop wrote:
> 
> 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 " ":

This has been improved in 3.09.1 ... from the Changelog:

- Printf: better handling of partial applications of the
  printf functions.

        Objective Caml version 3.09.1

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

Hurrah!  It always tripped me up :)

-- 
Anil Madhavapeddy                                 http://anil.recoil.org
University of Cambridge                          http://www.cl.cam.ac.uk


  reply	other threads:[~2006-01-22 16:27 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 ` [Caml-list] " Jon Harrop
2006-01-22 16:27   ` Anil Madhavapeddy [this message]
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=20060122162745.GA20731@fork.recoil.org \
    --to=anil@recoil.org \
    --cc=caml-list@inria.fr \
    --cc=jon@ffconsultancy.com \
    /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