caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolás Ojeda Bär" <nicolas.ojeda.bar@lexifi.com>
To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: Josh Berdine <josh@berdine.net>,
	"caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] Format questions
Date: Sun, 9 Apr 2017 09:45:06 +0200	[thread overview]
Message-ID: <CADK7aFNoYcfHPasZrL2WQTMRVd-yMup9V4it2Oom9KXk0Mu3+Q@mail.gmail.com> (raw)
In-Reply-To: <a6cac3cd-4546-c4d0-3b5c-1dce7db82dab@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2112 bytes --]

Hi Matej,

I do not think that is the reason, as both calls do the same thing, see

  https://github.com/ocaml/ocaml/blob/trunk/stdlib/format.ml#L1153

Cheers,
Nicolas


On Sun, Apr 9, 2017 at 9:44 AM, Matej Kosik <
5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:

> Hi Josh,
>
> On 04/09/2017 12:24 AM, Josh Berdine wrote:
> > On Sat, Apr 08 2017, Matej Kosik wrote:
> >
> >> Hi everybody,
> >>
> >> I am trying to understand the concepts in the Format module.
> >>
> >> While reading this:
> >>
> >>   https://ocaml.org/learn/tutorials/format.html
> >>
> >> One of the mini experiments I did was:
> >>
> >>   set_margin 11;
> >>   open_hvbox 0;
> >>   print_string "---";
> >>   print_space ();
> >>   print_string "---";
> >>   print_space ();
> >>   print_string "---";
> >>   print_newline ();
> >>   print_newline ();
> >>
> >> I've got the expected output, which is:
> >>
> >>   ---
> >>   ---
> >>   ---
> >>
> >> No surprises.
> >>
> >> However, when I tried to write express the same intentions via
> Format.fprintf function:
> >>
> >>   Format.set_margin 11;
> >>   Format.fprintf std_formatter "@[<hv 0>---@ ---@ ---@.@.";
> >>
> >> I get:
> >>
> >>   --- --- ---
> >>
> >> I'd like to ask for some clues as to why the output of the above
> Format.fprintf is different from the more verbose version above.
> >
> > Are you, by chance, evaluating this in utop (which seems to mess with
> std_formatter)?   I see your expected behavior using the standard
> toplevel.  (After adding Format. to std_formatter)
>
> I was using standard Ocaml toplevel
> (in a context where I opened Format module).
>
> I looked at it today and I have realized that instead of this:
>
>   set_margin 11;
>
> if I want to use "Format.fprintf std_formatter" I should do
>
>   pp_set_margin std_formatter 11;
>
> as if
>
>   set_margin <> pp_set_margin std_formatter
>
> That I did not know.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 3622 bytes --]

      reply	other threads:[~2017-04-09  7:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08 20:52 Matej Kosik
2017-04-08 22:24 ` Josh Berdine
2017-04-09  7:44   ` Matej Kosik
2017-04-09  7:45     ` Nicolás Ojeda Bär [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=CADK7aFNoYcfHPasZrL2WQTMRVd-yMup9V4it2Oom9KXk0Mu3+Q@mail.gmail.com \
    --to=nicolas.ojeda.bar@lexifi.com \
    --cc=5764c029b688c1c0d24a2e97cd764f@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=josh@berdine.net \
    /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).