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 FAA23505; Sun, 18 May 2003 05:32:32 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id FAA27500 for ; Sun, 18 May 2003 05:32:31 +0200 (MET DST) Received: from nexus.stwing.upenn.edu (NEXUS.STWING.UPENN.EDU [165.123.132.61]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h4I3WUH06958 for ; Sun, 18 May 2003 05:32:31 +0200 (MET DST) Received: from force.stwing.upenn.edu (daemon@force.stwing.upenn.edu [165.123.132.65]) by nexus.stwing.upenn.edu (8.12.9/8.12.9) with ESMTP id h4I3WTrb023654 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 17 May 2003 23:32:29 -0400 (EDT) Received: (from wlovas@localhost) by force.stwing.upenn.edu (8.12.9/8.12.9) id h4I3WTMN021317 for caml-list@inria.fr; Sat, 17 May 2003 23:32:29 -0400 (EDT) Date: Sat, 17 May 2003 23:32:28 -0400 From: William Lovas To: Ocaml Mailing List Subject: Re: [Caml-list] Printf question Message-ID: <20030518033228.GA21179@force.stwing.upenn.edu> Mail-Followup-To: Ocaml Mailing List References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-Spam: no; 0.00; lovas:01 wlovas:01 stwing:01 caml-list:01 printf:01 foo:01 outputs:01 prepend:01 kprintf:01 debug:01 continuation:02 string:03 wrote:03 let:04 william:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sat, May 17, 2003 at 08:34:27PM -0500, Brian Hurt wrote: > let debug s = Printf.printf ("FOO: " ^ s ^ "\n") > > and: > > let debug s = let t = "FOO: " ^ s ^ "\n" in Printf.printf s > > and neither works. This is due to the funny type magic that makes printf work in the first place. > debug "some message"; (* outputs "FOO: some message\n" *) > debug "answer: %d" 42 ; (* outputs "FOO: answer: 42\n" *) > > basically to prepend "FOO: " and append "\n". Is this possible in any > sane manner? I tried: I think the right solution (or at least, *a* right solution) in this case is to use kprintf, which takes a continuation to pass the resulting string to. For an sprintf-like solution: let debug s = Printf.kprintf (fun t -> "FOO: " ^ t ^ "\n") s Or, for something more side-effectual: let debug s = Printf.kprintf (fun t -> print_string ("FOO: " ^ t ^ "\n"); "") s (But you might have to use `ignore' to ignore the useless empty string result value.) cheers, William ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners