From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA08987; Tue, 12 Jun 2001 21:03:57 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA08993 for ; Tue, 12 Jun 2001 21:03:56 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f5CJ3ub19014 for ; Tue, 12 Jun 2001 21:03:56 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id VAA01649; Tue, 12 Jun 2001 21:03:43 +0200 (MET DST) Date: Tue, 12 Jun 2001 21:03:42 +0200 From: Markus Mottl To: Chris Hecker Cc: caml-list@inria.fr Subject: Re: [Caml-list] pretty printers and format and matrices Message-ID: <20010612210342.A662@miss.wu-wien.ac.at> References: <4.3.2.7.2.20010612111351.029b8720@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <4.3.2.7.2.20010612111351.029b8720@shell16.ba.best.com>; from checker@d6.com on Tue, Jun 12, 2001 at 11:18:13 -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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