From: Jiten Pathy <jpathy@fssrv.net>
To: David Allsopp <dra-news@metastack.com>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] format strings
Date: Tue, 10 Feb 2015 00:34:45 -0800 [thread overview]
Message-ID: <CAL2Z3DAhTwkEZbVqfEnwDvu9qFxKR=yi7ZrmwjCGik1nEe53fw@mail.gmail.com> (raw)
In-Reply-To: <E51C5B015DBD1348A1D85763337FB6D9E98D809A@Remus.metastack.local>
Thanks, that helps. I can't think of any complicated manipulation i
would need, for now.
On Tue, Feb 10, 2015 at 12:25 AM, David Allsopp <dra-news@metastack.com> wrote:
> Jiten Pathy wrote:
>> Ok, If i am not supposed to use make_printf, then what is the recommended
>> way of writing the following?
>>
>> This adds a new line to given format string. In particular how do i
>> manipulate the format strings passed to me?
>
> There wasn't a vast amount of type-safe manipulation possible with format strings in the old implementation, though given the newer representation, perhaps something may come in the future.
>
>> open CamlinternalFormat;;
>> let f (Format (fmt, _)) =
>> make_printf (fun o acc -> output_acc o (Acc_char_literal (acc, '\n'));
>> ignore o) stdout End_of_acc fmt ;; val f : ('a, out_channel, unit, unit,
>> unit, unit) format6 -> 'a = <fun>
>>
>> utop # f "%s %d" "# " 3;;
>> # 3
>> - : unit = ()
>
> However, for this "simple" manipulation there are two ways which don't touch the internals:
>
> let f fmt = Printf.ksprintf (Printf.printf "%s\n") fmt
>
> [that's my preference - to me it's clearer that you're wrapping the formatted output. I'd often do this to add %! as well - i.e. "%s\n%!"]
>
> let f fmt = Printf.printf (fmt ^^ "\n")
>
> [See http://caml.inria.fr/pub/docs/manual-ocaml-4.02/libref/Pervasives.html#6_Operationsonformatstrings]
>
>
> David
prev parent reply other threads:[~2015-02-10 8:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 11:58 Jiten Pathy
2015-02-09 12:25 ` John F Carr
2015-02-09 16:28 ` Jiten Pathy
2015-02-09 17:32 ` David Allsopp
2015-02-10 1:05 ` Jiten Pathy
2015-02-10 2:47 ` Jiten Pathy
2015-02-10 7:44 ` David Allsopp
2015-02-10 7:55 ` Jiten Pathy
2015-02-10 8:25 ` David Allsopp
2015-02-10 8:34 ` Jiten Pathy [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='CAL2Z3DAhTwkEZbVqfEnwDvu9qFxKR=yi7ZrmwjCGik1nEe53fw@mail.gmail.com' \
--to=jpathy@fssrv.net \
--cc=caml-list@inria.fr \
--cc=dra-news@metastack.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