* [Caml-list] pretty printers and format and matrices @ 2001-06-12 18:18 Chris Hecker 2001-06-12 19:03 ` Markus Mottl 0 siblings, 1 reply; 12+ messages in thread From: Chris Hecker @ 2001-06-12 18:18 UTC (permalink / raw) To: caml-list Format has come up on the list a couple times, so I figured I'd ask a question I gave up on trying to solve a while back. I'd like to write a printer for the top level that will print out matrices as rectangular blocks of numbers, not lists of numbers. I couldn't figure out whether this was possible with install_printer in a clean way. The obvious things didn't work quite right. I finally gave up and ended up with this (open Bigarray first): let print2d a = for i = 0 to Array2.dim1 a - 1 do for j = 0 to Array2.dim2 a - 1 do Format.printf "%f\t" a.{i,j} done; Format.printf "\n"; done But this doesn't play nice with other printers like it should. I tried a few different attemps at putting the boxes in, but none worked. I also read the FAQ, but couldn't quite apply its info to this problem. Is there a "right" way to do this, or is the Format module not set up for vertical printing? Chris ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-12 18:18 [Caml-list] pretty printers and format and matrices Chris Hecker @ 2001-06-12 19:03 ` Markus Mottl 2001-06-12 21:01 ` Chris Hecker 0 siblings, 1 reply; 12+ messages in thread From: Markus Mottl @ 2001-06-12 19:03 UTC (permalink / raw) To: Chris Hecker; +Cc: caml-list On Tue, 12 Jun 2001, Chris Hecker wrote: > Format has come up on the list a couple times, so I figured I'd ask > a question I gave up on trying to solve a while back. Once one gets used to it, it's really fun so don't give up... > I finally gave up and ended up with this (open Bigarray first): > > let print2d a = > for i = 0 to Array2.dim1 a - 1 do > for j = 0 to Array2.dim2 a - 1 do > Format.printf "%f\t" a.{i,j} > done; > Format.printf "\n"; > done The reason is obviously the use of "\n": this is a "real" newline, which disregards indentation levels. The pretty printer will still assume that it hasn't broken lines if you use this, which makes further output look really strange. > But this doesn't play nice with other printers like it should. I tried > a few different attemps at putting the boxes in, but none worked. > I also read the FAQ, but couldn't quite apply its info to this problem. > Is there a "right" way to do this, or is the Format module not set up > for vertical printing? You'll have to use "@\n" instead or also "Format.force_newline ()" if you want to force a newline without confusing indentation levels. The Format-module is very powerful! In most cases it will suffice if you use hov-boxes (the default with "@[") + indentation annotations as required. Try this for instance: --------------------------------------------------------------------------- open Bigarray open Format let print2d ppf a = fprintf ppf "@[<2>[|"; for i = 0 to Array2.dim1 a - 1 do pp_force_newline ppf (); for j = 0 to Array2.dim2 a - 1 do fprintf ppf "%f;\t" a.{i,j} done done; fprintf ppf "@]@\n|]" let _ = let ar = Array2.of_array float32 c_layout [|[|1.; 2.|]; [|3.; 4.|]|] in printf "%a@\n" print2d ar --------------------------------------------------------------------------- Regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-12 19:03 ` Markus Mottl @ 2001-06-12 21:01 ` Chris Hecker 2001-06-13 12:16 ` Hendrik Tews 2001-06-14 6:46 ` Pierre Weis 0 siblings, 2 replies; 12+ messages in thread From: Chris Hecker @ 2001-06-12 21:01 UTC (permalink / raw) To: Markus Mottl; +Cc: caml-list >Once one gets used to it, it's really fun so don't give up... I had the choice of "try to get the formatting working for no other reason than curiosity" or "write more real code on my game", so the latter edged it out. :) > let print2d ppf a = This works better, thanks! I swear I tried something exactly like that... There's a tiny bit of weirdness with the tabs after the first column, but it's way better than what I had. I definitely tried the @\n, but I admit I was randomly typing at that point. The docs could stand to be a bit clearer on newlines versus breaks. Perhaps your print2d would make a good complementary tutorial to the expression printer in the FAQ... Thanks, Chris ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-12 21:01 ` Chris Hecker @ 2001-06-13 12:16 ` Hendrik Tews 2001-06-14 19:37 ` Pierre Weis 2001-06-14 6:46 ` Pierre Weis 1 sibling, 1 reply; 12+ messages in thread From: Hendrik Tews @ 2001-06-13 12:16 UTC (permalink / raw) To: caml-list Hi, I have another question about the format module: How can I set max_boxes to infinity? We use the format module to output source code of a programming language. For that one needs a way to advice the format module to print everything, regardless of how deep boxes are nested. At the moment we use (set_max_boxes 1000), and when we run into problems we increase the number. Bye, Hendrik ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-13 12:16 ` Hendrik Tews @ 2001-06-14 19:37 ` Pierre Weis 2001-06-14 19:58 ` Patrick M Doane ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Pierre Weis @ 2001-06-14 19:37 UTC (permalink / raw) To: Hendrik Tews; +Cc: caml-list > Hi, > > I have another question about the format module: > > How can I set max_boxes to infinity? > > We use the format module to output source code of a programming > language. For that one needs a way to advice the format module to > print everything, regardless of how deep boxes are nested. At the > moment we use (set_max_boxes 1000), and when we run into problems > we increase the number. > > > Bye, > > Hendrik > ------------------- > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Having to open more than 1000 boxes to print any material seems incredible to me, since I used to pretty print an entire Caml compiler within 35 boxes. Anyway, I'm afraid there is no notion of infinity in Format. Neither in the Caml integer values. Hence no solution to your problem. The best you can do is to use a rough approximation, as in: set_max_boxes max_int;; On a regular machine this allows to simultaneously open no more than 4611686018427387903 boxes, which could be large enough to pretty print a huge source chunk of your programming language source programs. On the other hand, on my Ipaq handheld this limit is much smaller than that, namely 1073741823 which may be really short for you. If you need more than max_int simultaneously open boxes, you should rewrite the Format module using the bignumbers facility of Caml. However, I should admit that you will still be facing another stupid limit (no more than 2^30 words in a big integer, which means approximately 9 * 2 ^ 30 decimal digits on a little machine, once more far far away from infinity). If you really need infinity, I am not aware of any practical solution in Objective Caml. Sorry for this unsatisfactory answer, due to stupid limitations in the language. Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-14 19:37 ` Pierre Weis @ 2001-06-14 19:58 ` Patrick M Doane 2001-06-14 20:36 ` Pierre Weis 2001-06-14 21:35 ` Frank Atanassow 2001-06-15 12:34 ` Hendrik Tews 2 siblings, 1 reply; 12+ messages in thread From: Patrick M Doane @ 2001-06-14 19:58 UTC (permalink / raw) To: Pierre Weis; +Cc: Hendrik Tews, caml-list On Thu, 14 Jun 2001, Pierre Weis wrote: > Having to open more than 1000 boxes to print any material seems > incredible to me, since I used to pretty print an entire Caml compiler > within 35 boxes. > > Anyway, I'm afraid there is no notion of infinity in Format. Neither > in the Caml integer values. Hence no solution to your problem. Would it be reasonable to increase the default value from 35? Are there any performance problems with setting this value to max_int in the pp_make_formatter routine? Patrick ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-14 19:58 ` Patrick M Doane @ 2001-06-14 20:36 ` Pierre Weis 0 siblings, 0 replies; 12+ messages in thread From: Pierre Weis @ 2001-06-14 20:36 UTC (permalink / raw) To: Patrick M Doane; +Cc: caml-list > On Thu, 14 Jun 2001, Pierre Weis wrote: > > > Having to open more than 1000 boxes to print any material seems > > incredible to me, since I used to pretty print an entire Caml compiler > > within 35 boxes. > > > > Anyway, I'm afraid there is no notion of infinity in Format. Neither > > in the Caml integer values. Hence no solution to your problem. > > Would it be reasonable to increase the default value from 35? Are there > any performance problems with setting this value to max_int in the > pp_make_formatter routine? > > Patrick > > ------------------- > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Yes, setting the default value to the maximum possible value is conceivable. However, this (reasonable) limit is there as a kind of alert to tell the user that the number of boxes the programs opens is now considered large (hence you may consider having a look at the printing program to see if it works properly). This is the performance problem you may have (not in the library but in your printing routines). However if this is generally agreed, we can do it ... Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-14 19:37 ` Pierre Weis 2001-06-14 19:58 ` Patrick M Doane @ 2001-06-14 21:35 ` Frank Atanassow 2001-06-15 12:43 ` Pierre Weis 2001-06-15 12:34 ` Hendrik Tews 2 siblings, 1 reply; 12+ messages in thread From: Frank Atanassow @ 2001-06-14 21:35 UTC (permalink / raw) To: Pierre Weis; +Cc: Hendrik Tews, caml-list Pierre Weis wrote (on 14-06-01 21:37 +0200): > On a regular machine this allows to simultaneously open no more than > 4611686018427387903 boxes, which could be large enough to pretty print > a huge source chunk of your programming language source programs. On > the other hand, on my Ipaq handheld this limit is much smaller than > that, namely 1073741823 which may be really short for you. > > If you need more than max_int simultaneously open boxes, you should > rewrite the Format module using the bignumbers facility of > Caml. However, I should admit that you will still be facing another > stupid limit (no more than 2^30 words in a big integer, which means > approximately 9 * 2 ^ 30 decimal digits on a little machine, once more > far far away from infinity). If you really need infinity, I am not aware > of any practical solution in Objective Caml. > > Sorry for this unsatisfactory answer, due to stupid limitations in the > language. Obviously the solution is to rewrite Format so that the box numbers are encoded as Church numerals. Then you can easily represent infinity: let zero = fun z s -> z;; let succ n = fun z s -> let s' = s () in s' (n z s);; (* unfortunately, eta-expansion needed because of value restriction *) let one = fun z s -> succ zero z s;; let two = fun z s -> succ one z s;; let three = fun z s -> succ two z s;; ... let rec infty = fun z s -> let s' = s () in s' (infty z s);; let eq m n = m (fun () let add m n = m n (fun () -> succ);; let print_num n = n () (fun () -> print_string "1"; fun _ -> ());; # print_num one;; 1- : unit = () # print_num (add two three);; 11111- : unit = () # print_num infty;; 111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111 11111111111111111111Interrupted. # print_num (succ infty);; 111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111111111111111111111111111111111111111111111111111111 111111111111111111111Interrupted. P.S.: When I started writing this, I thought Pierre's post was in jest. Now I'm not so sure anymore...! -- Frank Atanassow, Information & Computing Sciences, Utrecht University Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands Tel +31 (030) 253-3261 Fax +31 (030) 251-379 ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-14 21:35 ` Frank Atanassow @ 2001-06-15 12:43 ` Pierre Weis 0 siblings, 0 replies; 12+ messages in thread From: Pierre Weis @ 2001-06-15 12:43 UTC (permalink / raw) To: Frank Atanassow; +Cc: Pierre.Weis, tews, caml-list > P.S.: When I started writing this, I thought Pierre's post was in jest. Now > I'm not so sure anymore...! Nor am I! :) Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-14 19:37 ` Pierre Weis 2001-06-14 19:58 ` Patrick M Doane 2001-06-14 21:35 ` Frank Atanassow @ 2001-06-15 12:34 ` Hendrik Tews 2001-06-15 17:32 ` Pierre Weis 2 siblings, 1 reply; 12+ messages in thread From: Hendrik Tews @ 2001-06-15 12:34 UTC (permalink / raw) To: caml-list Hi, Pierre Weis writes: Date: Thu, 14 Jun 2001 21:37:44 +0200 (MET DST) Subject: Re: [Caml-list] pretty printers and format and matrices However, I should admit that you will still be facing another stupid limit (no more than 2^30 words in a big integer, which means approximately 9 * 2 ^ 30 decimal digits on a little machine, once more far far away from infinity). OK, I see you are in sarcastic mood ... I am actually negotiating with John Skaller the foundation of the "Got bitten by Pierre Club", anybody else who wants to participate? ;-) Sorry for this unsatisfactory answer, due to stupid limitations in the language. Then I would like to suggest to add a new feature to a future version of the format module: "do_never_print_ellipsis". Perhaps (set_max_boxes -1) could be interpreded this way. Problems like "The most interesting problem repaired by the Judges was that one entry nested Objective Caml's Format boxes too deeply ....", quoted from [1], would then belong to the past. BTW: set_max_boxes max_int;; On a regular machine this allows to simultaneously open no more than 4611686018427387903 boxes, which could be large enough to pretty print I have # max_int;; - : int = 1073741823 so what's a regular machine?? Thanks anyway for the unsatisfactory answer, Hendrik [1] The 1999 ICFP Programming Contest. ACM SIGPLAN Notices, 35(3), pp. 73-83, March 2000. Available at http://www.eecs.harvard.edu/~nr/pubs/icfp99.ps ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-15 12:34 ` Hendrik Tews @ 2001-06-15 17:32 ` Pierre Weis 0 siblings, 0 replies; 12+ messages in thread From: Pierre Weis @ 2001-06-15 17:32 UTC (permalink / raw) To: Hendrik Tews; +Cc: caml-list Hi, > Pierre Weis writes: > Date: Thu, 14 Jun 2001 21:37:44 +0200 (MET DST) > Subject: Re: [Caml-list] pretty printers and format and matrices > > However, I should admit that you will still be facing another > stupid limit (no more than 2^30 words in a big integer, which means > approximately 9 * 2 ^ 30 decimal digits on a little machine, once more > far far away from infinity). > > OK, I see you are in sarcastic mood ... I am actually negotiating > with John Skaller the foundation of the "Got bitten by Pierre > Club", anybody else who wants to participate? > ;-) Sorry for that I was just a bit tired by a more than 5 hours long meeting. I was also taking it for granting that everybody would understand that I was joking: could you imagine opening so much boxes that it could overflow a limit which is as large as a number that has ``9 * 2 ^ 30 decimal digits'' ? Could you imagine anything real (such that a computation or something that you can count) that can overflow such a huge number (much much bigger than even a google) ? Also, I don't know if we have to permanently be calm and solemn when posting to this mailing list. Well, I guess it's the best way given the medium ... > Sorry for this unsatisfactory answer, due to stupid limitations in the > language. > > Then I would like to suggest to add a new feature to a future > version of the format module: "do_never_print_ellipsis". Perhaps > (set_max_boxes -1) could be interpreded this way. This way of interpreting negative numbers seems a bit strange to me. Also this would add a lot of particular cases, just for people who need more than 1073741823 simultaneously open boxes (just have a look to this number, it is really huge indeed). > Problems like "The most interesting problem repaired by the > Judges was that one entry nested Objective Caml's Format boxes > too deeply ....", quoted from [1], would then belong to the past. OK, you win. Then I would prefer to set pp_max_boxes to max_int at creation time of the ``formatter''. This is simpler and more logical... > BTW: > > set_max_boxes max_int;; > > On a regular machine this allows to simultaneously open no more than > 4611686018427387903 boxes, which could be large enough to pretty print > > I have > > # max_int;; > - : int = 1073741823 > > so what's a regular machine?? Sorry for that also, you need some context to understand that one: a ``regular'' machine is a kind of nickname we used here to name our 64 bits alpha machines, I suppose that this is a way to insist on the fact that there exist other processors than Intel's ... > Thanks anyway for the unsatisfactory answer, You're very welcome. > Hendrik > > > [1] The 1999 ICFP Programming Contest. ACM SIGPLAN Notices, > 35(3), pp. 73-83, March 2000. Available at > http://www.eecs.harvard.edu/~nr/pubs/icfp99.ps Regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Caml-list] pretty printers and format and matrices 2001-06-12 21:01 ` Chris Hecker 2001-06-13 12:16 ` Hendrik Tews @ 2001-06-14 6:46 ` Pierre Weis 1 sibling, 0 replies; 12+ messages in thread From: Pierre Weis @ 2001-06-14 6:46 UTC (permalink / raw) To: Chris Hecker; +Cc: caml-list > > >Once one gets used to it, it's really fun so don't give up... > > I had the choice of "try to get the formatting working for no other > reason than curiosity" or "write more real code on my game", so the > latter edged it out. :) > > > let print2d ppf a = > > This works better, thanks! I swear I tried something exactly like that... > > There's a tiny bit of weirdness with the tabs after the first > column, but it's way better than what I had. I definitely tried the > @\n, but I admit I was randomly typing at that point. The docs > could stand to be a bit clearer on newlines versus breaks. Perhaps > your print2d would make a good complementary tutorial to the > expression printer in the FAQ... > > Thanks, > Chris Have you read the special paragraph devoted to Format in the FAQ ? http://pauillac.inria.fr/caml/FAQ/format-eng.html It says somewhere: Practice When writing a pretty-printing routine, follow these simple rules: [...] 4.Don't try to force line breaking, let the pretty-printer do it for you: that's its only job. 5.End your main program by a print_newline () call, that flushes the pretty-printer tables (hence the ouput). (Note that the toplevel loop of the interactive system does it as well, just before a new input.) Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2001-06-15 17:32 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2001-06-12 18:18 [Caml-list] pretty printers and format and matrices Chris Hecker 2001-06-12 19:03 ` Markus Mottl 2001-06-12 21:01 ` Chris Hecker 2001-06-13 12:16 ` Hendrik Tews 2001-06-14 19:37 ` Pierre Weis 2001-06-14 19:58 ` Patrick M Doane 2001-06-14 20:36 ` Pierre Weis 2001-06-14 21:35 ` Frank Atanassow 2001-06-15 12:43 ` Pierre Weis 2001-06-15 12:34 ` Hendrik Tews 2001-06-15 17:32 ` Pierre Weis 2001-06-14 6:46 ` Pierre Weis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox