I would like to print a list of fun
’s like the following, if space permits:
(fun1(); fun2(); fun3())
We may notice that:
- there is not SPACE between the first
(
withfun1
- there is not SPACE between the last
)
withfun3()
When space is not enough, we should see:
(
fun1();
fun2();
fun3()
)
We may notice that both the first (
and last )
are the only element in their line.
Here’s my demo:
open PPrint
let document =
hardline
^^ group
(string "("
^^ nest 2
(break 1
^^ group (string "fun1();" ^/^ string "fun2();" ^/^ string "fun3()")
)
^/^ string ")")
^^ hardline
let document2 =
hardline
^^ group
(string "("
^^ nest 2
(break 0
^^ group (string "fun1();" ^/^ string "fun2();" ^/^ string "fun3()")
)
^^ string ")")
^^ hardline
let document3 =
hardline
^^ group
(string "("
^^ nest 2
(break 0
^^ group (string "fun1();" ^/^ string "fun2();" ^/^ string "fun3()")
)
^/^ string ")")
^^ hardline
let () =
ToChannel.pretty 0.5 20 stdout document;
flush stdout;
ToChannel.pretty 0.5 60 stdout document;
flush stdout;
ToChannel.pretty 0.5 20 stdout document2;
flush stdout;
ToChannel.pretty 0.5 60 stdout document2;
flush stdout;
ToChannel.pretty 0.5 20 stdout document3;
flush stdout;
ToChannel.pretty 0.5 60 stdout document3;
flush stdout
It outputs as follows:
# document
(
fun1();
fun2();
fun3()
)
( fun1(); fun2(); fun3() )
# document2
(
fun1();
fun2();
fun3())
(fun1(); fun2(); fun3())
# document3
(
fun1();
fun2();
fun3()
)
(fun1(); fun2(); fun3() )
The results:
-
document
: There’re additional space between(
andfun1()
. -
document2
:fun3())
, the last)
should in next line. -
document3
: There’s additional space betweenfun3()
and the last)