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 AAA21149; Tue, 30 Sep 2003 00:37: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 AAA01511 for ; Tue, 30 Sep 2003 00:37:31 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8TMaxH11902; Tue, 30 Sep 2003 00:36:59 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA23653; Tue, 30 Sep 2003 00:36:59 +0200 (MET DST) From: Pierre Weis Message-Id: <200309292236.AAA23653@pauillac.inria.fr> Subject: Re: [Caml-list] Printf question In-Reply-To: <20030929215008.GA15057@redhat.com> from Richard Jones at "Sep 29, 103 10:50:08 pm" To: rich@annexia.org (Richard Jones) Date: Tue, 30 Sep 2003 00:36:59 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 pierre:01 weis:01 caml-list:01 printf:01 quoting:01 printf:01 fprintf:01 val:01 quoting:01 sth:99 sth:99 salary:01 emp:99 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > On Mon, Sep 29, 2003 at 09:57:19PM +0200, Pierre Weis wrote: > > Hence, I think you are seeking for the %a conversion. For instance, > > defining a quotation function for SQL as in > > > > # let sql_quoting oc = Printf.fprintf oc "'%s'";; > > val sql_quoting : out_channel -> string -> unit = > > > > You can define sth with a %a conversion to apply quoting on the fly: > > > > # let sth x = > > prepare "select salary from emp where id = %d and name = %a" x;; > > val sth : int -> (out_channel -> 'a -> unit) -> 'a -> unit = > > > > # sth 1 sql_quoting "Jones";; > > select salary from emp where id = 1 and name = 'Jones'- : unit = () > > > > Still fully type-checked! Sounds better, no ? > > Hmmm ... but as I explained earlier, that's really not type safe > at all. > > Rich. What do you mean by ``not type safe at all'' ? The common acceptation is ``it could lead to type errors at runtime''. If you ever exhibit such a problem with format strings, please show us a complete example, since you indeed discovered an unpleasant bug in the compiler :( Remember that our claim for the printf/scanf and format strings implementation is the same as for the rest of the language: programs are safe and can never go wrong (i.e. they never produce bus errors or jeopardize type safety). (To be precise, this claim evidently does not apply to programs that could use faulty interfaces with foreign languages, functions from the Obj module, uncautious input_value/output_value calls, or are compiled with the -unsafe option.) Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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