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 MAA28399; Thu, 16 Aug 2001 12:06:15 +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 MAA28379 for ; Thu, 16 Aug 2001 12:06:14 +0200 (MET DST) Received: from lantana.wanadoo.fr (smtp-rt-8.wanadoo.fr [193.252.19.51]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7GA6D523938 for ; Thu, 16 Aug 2001 12:06:13 +0200 (MET DST) Received: from amyris.wanadoo.fr (193.252.19.150) by lantana.wanadoo.fr; 16 Aug 2001 12:06:13 +0200 Received: from debian (195.6.77.9) by amyris.wanadoo.fr; 16 Aug 2001 12:06:04 +0200 Received: from moi by debian with local (Exim 3.32 #1 (Debian)) id 15XJR4-0000NP-00 for ; Thu, 16 Aug 2001 11:27:30 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Printf.sprintf ? References: From: Remi VANICAT Date: 16 Aug 2001 11:27:30 +0200 In-Reply-To: Message-ID: <87d75wxsl9.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.104 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Brian Rogoff writes: > Because Printf is a bit of a hack, in that the syntax for a format string > is the same as the syntax for a regular string. As a beginner, when you > use Printf, it's easier to use the format string as a literal and not > as a variable. If you feel you must do this, the polite way is as follows > > # let q = ("%s" : ('a, 'b, 'c) format);; > val q : (string -> 'a, 'b, 'a) format = > # let s = Printf.sprintf q "enigiets";; > val s : string = "enigiets" > > and there's also a rude way (forgive me Berke! :) > > let s : string = Printf.sprintf (Obj.magic q) "enigiets";; it's often not a good idea : # let q = "%s";; val q : string = "%s" # let s : string = Printf.sprintf (Obj.magic q)0;; Segmentation fault moi@debian:~$ this break the type system. better use the first solution. -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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