caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
To: 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:44:36 +0200	[thread overview]
Message-ID: <a6cac3cd-4546-c4d0-3b5c-1dce7db82dab@gmail.com> (raw)
In-Reply-To: <jk60ig1st2bkrt.fsf@fb.com>

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.

  reply	other threads:[~2017-04-09  7:38 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 [this message]
2017-04-09  7:45     ` Nicolás Ojeda Bär

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=a6cac3cd-4546-c4d0-3b5c-1dce7db82dab@gmail.com \
    --to=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).