caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Understanding Format
@ 2012-07-23  9:05 Alain Frisch
  2012-07-24 13:16 ` Olivier Andrieu
  0 siblings, 1 reply; 2+ messages in thread
From: Alain Frisch @ 2012-07-23  9:05 UTC (permalink / raw)
  To: caml-list

Hi all,

I'm trying to understand the semantics of Format boxes, and I need some 
help!  Consider the following:

let () =
   set_margin 500;
   open_vbox 0;
   for _i = 1 to 300 do
     open_hbox ();
     print_string "x";
     close_box ()
   done;
   close_box ()


Format inserts line breaks, even though the page width (margin) should 
be large enough to contain 300 characters (and there is no break hint 
anyway). Why does it do it?   Changing the value passed to set_margin 
does not seem to make a difference (except for small values < 70).

I'm also interest in understanding the performance of Format. In the 
example above, changing 300 to 1000000, the program takes about 0.6s to 
execute on my machine.  This does not seem to be impacted by the value 
passed to set_margin... except for large values (like max_int), where 
the program takes about 1s.  Is this slowdown for "unbounded" width 
expected?  (Interestingly, despite this slowdown, the unbounded-width 
version allocates less than the bounded-width case.)


Alain

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Understanding Format
  2012-07-23  9:05 [Caml-list] Understanding Format Alain Frisch
@ 2012-07-24 13:16 ` Olivier Andrieu
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier Andrieu @ 2012-07-24 13:16 UTC (permalink / raw)
  To: Alain Frisch; +Cc: caml-list

Salut,

On Mon, Jul 23, 2012 at 11:05 AM, Alain Frisch <alain@frisch.fr> wrote:
> Hi all,
>
> I'm trying to understand the semantics of Format boxes, and I need some
> help!  Consider the following:
>
> let () =
>   set_margin 500;
>   open_vbox 0;
>   for _i = 1 to 300 do
>     open_hbox ();
>     print_string "x";
>     close_box ()
>   done;
>   close_box ()
>
>
> Format inserts line breaks, even though the page width (margin) should be
> large enough to contain 300 characters (and there is no break hint anyway).
> Why does it do it?   Changing the value passed to set_margin does not seem
> to make a difference (except for small values < 70).

You have to increase the 'max_indent' parameter for the formatter too :
  http://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html#VALset_max_indent

When you open your hbox, you get an implicit break if the current
cursor position is past this max_ident.
Calling set_margin does not change max_indent which keeps its default
value (68).

cf. this comment in format.ml :
(* To indent no more than pp_max_indent, if one tries to open a block
   beyond pp_max_indent, then the block is rejected on the left
   by simulating a break.
*)

HTH
-- 
  Olivier

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-24 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-23  9:05 [Caml-list] Understanding Format Alain Frisch
2012-07-24 13:16 ` Olivier Andrieu

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).