Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:07:41+00:00 2026-06-11T20:07:41+00:00

There is an example on the Using the Format module page on the OCaml

  • 0

There is an example on the Using the Format module page on the OCaml web site that gives an example of the differences between structural and packing hov boxes. I am trying to replicate this example. (I am using OCaml 3.12.1.)

With the following input:

Format.printf "@[<hov 2>(---@\n@[<hov 2>(---@\n@[<hov 2>(---@,)@]@,)@]@,)@]@\n"

I get the expected output:

(---
  (---
    (---)))

What I can not figure out is how to get the output the page ascribes to “structural boxes”:

(---
  (---
    (---
    )
  )
)

I was uncertain as to which Format.printf identifier maps to these boxes, so I tried several variations:

Format.printf "@[<hv 2>(---@\n@[<hv 2>(---@\n@[<hv 2>(---@,)@]@,)@]@,)@]@\n"
Format.printf "@[<2>(---@\n@[<2>(---@\n@[<2>(---@,)@]@,)@]@,)@]@\n"
Format.printf "@[<b 2>(---@\n@[<b 2>(---@\n@[<b 2>(---@,)@]@,)@]@,)@]@\n"

But all of the above give the same output as with the <hov 2> initial example. Would anyone have any ideas how I can get output similar to the second example from web page?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:07:42+00:00Added an answer on June 11, 2026 at 8:07 pm

    I would have thought that your second example (with hv boxes) should work. But it seems that @\n does not have the behavior we expect.

    Solution 1: force the line break before the right parenthesis, i.e. replace @, by @\n.

    let () =
      Format.printf "@.";
      Format.printf "@[<hov 2>(---@\n@[<hov 2>(---@\n@[<hov 2>(---@\n)@]@\n)@]@\n)@]@\n";
      Format.printf "@."
    

    Result:

    (---
      (---
        (---
          )
        )
      )
    

    Problem: there will always be a line break, it will never print:

    (—(—(—)))

    even if it has the room for it. If that is an issue for you, see solution 2.

    Solution 2: Use longer lines 🙂 If the break is caused by a long line then an hv box does break the line before the closing parenthesis.

    let () =
      Format.printf "@.";
      Format.printf "@[<hv 2>(------------------------------------------------------------------------@,@[<hv 2>(---@,@[<hv 2>(---@,)@]@,)@]@,)@]";
      Format.printf "@."
    

    Result:

    (------------------------------------------------------------------------
      (---(---))
      )
    

    However, the closing parenthesis is not aligned with the opening one.

    Solution 3: If you want the right parenthesis to be aligned with the left one, you need
    two boxes.

    let () =
      Format.printf "@.";
      Format.printf
        "@[<hv>@[<hv 2>(------------------------------------------------------------------------\
         @[<hv>@[<hv 2>(------------------------------------------------------------------------\
         @[<hv>@[<hv 2>(------------------------------------------------------------------------\
         @]@,)@]@]@,)@]@]@,)@]";
      Format.printf "@."
    

    Result:

    (------------------------------------------------------------------------
      (------------------------------------------------------------------------
        (------------------------------------------------------------------------
        )
      )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are any differences between using SetValue with (for example) Canvas.LeftProperty and Margin Property?
I'm learning JavaScript and there's an example in the book I'm using that I
When using the python struct module on can specify a format string that declares
is there any example on using java method to call rhino-javascript function and return
Is there any example for a Real Time Chart using the DexExpress in ASP.Net?
There is an example on Adobe livedocs for using states : <!-- Define one
I'm using Schaum's Outline of Programming With Fortran 77 book, and there's an example
Using the Programming F# book, there's an example first given as serial: let result1
I'm using PHP in order to redirect some search query. There is some example
I'm using the facedetect example and going from there. Right now it only detects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.