Hi Josh,
I was using standard Ocaml toplevel
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)
(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