caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Printf question
@ 2003-09-26 18:02 Richard Jones
  2003-09-26 19:04 ` Alain.Frisch
  2003-09-27  0:11 ` Olivier Andrieu
  0 siblings, 2 replies; 28+ messages in thread
From: Richard Jones @ 2003-09-26 18:02 UTC (permalink / raw)
  To: caml-list

I want to write a function which is a bit like Printf.printf, but
handles the %s placeholder differently. It needs to do SQL-style
escaping, eg:

	my_printf "The string: %s" "string with 'quotes'"

would return the string:

	The string: 'string with ''quotes'''

(hope I've got that right ...)

Anyway, it looks like this should be possible, and possibly even quite
simple, with a custom formatter.

Can anyone give me a clue about this? Is Printf.printf implemented in
pure OCaml, or does it require trickery in the compiler to work? The
code is scarily complex ...

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/

-------------------
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


^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Caml-list] Printf question
@ 2003-05-18  1:34 Brian Hurt
  2003-05-18  3:23 ` Manos Renieris
                   ` (2 more replies)
  0 siblings, 3 replies; 28+ messages in thread
From: Brian Hurt @ 2003-05-18  1:34 UTC (permalink / raw)
  To: Ocaml Mailing List


I want to define a wrapper function for printf, basically for debug.  I'd 
like it to work so I can do things like:

    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:

let debug s = Printf.printf ("FOO: " ^ s ^ "\n")

and:

let debug s = let t = "FOO: " ^ s ^ "\n" in Printf.printf s

and neither works.

Brian


-------------------
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


^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2003-10-01 16:21 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-26 18:02 [Caml-list] Printf question Richard Jones
2003-09-26 19:04 ` Alain.Frisch
2003-09-29  7:44   ` Mike Potanin
2003-09-27  0:11 ` Olivier Andrieu
2003-09-27  7:23   ` Richard Jones
2003-09-27  8:20     ` Basile Starynkevitch
2003-09-27  9:14       ` Richard Jones
2003-09-27  9:39         ` Maxence Guesdon
2003-09-29 16:42         ` Pierre Weis
2003-09-29 18:13           ` Richard Jones
2003-09-29 19:57             ` Pierre Weis
2003-09-29 21:50               ` Richard Jones
2003-09-29 22:36                 ` Pierre Weis
2003-09-30  8:03                   ` Richard Jones
2003-09-30  8:45                     ` Pierre Weis
2003-09-30  9:17                       ` Michal Moskal
2003-09-30 14:14                         ` Christophe TROESTLER
2003-09-30 13:19                   ` skaller
2003-09-30 20:52                     ` Pierre Weis
2003-10-01 14:39                       ` Christophe TROESTLER
2003-10-01 14:57                         ` Richard Jones
2003-10-01 15:52                           ` [Caml-list] DBI (was: Printf question) Christophe TROESTLER
2003-10-01 16:21                         ` [Caml-list] Printf question Florian Hars
  -- strict thread matches above, loose matches on Subject: below --
2003-05-18  1:34 Brian Hurt
2003-05-18  3:23 ` Manos Renieris
2003-05-18  3:32 ` William Lovas
2003-05-18  6:06 ` Basile STARYNKEVITCH
2003-05-19  9:39   ` Damien

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).