* printf and positional specifier @ 2006-11-11 20:12 Anastasia Gornostaeva 2006-11-11 20:35 ` [Caml-list] " Peter Gregory 0 siblings, 1 reply; 8+ messages in thread From: Anastasia Gornostaeva @ 2006-11-11 20:12 UTC (permalink / raw) To: caml-list Hello. $ ocaml Objective Caml version 3.09.3 # open Printf;; # printf "%2$d %1$s" "abc" 2;; Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' How? ermine ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 20:12 printf and positional specifier Anastasia Gornostaeva @ 2006-11-11 20:35 ` Peter Gregory 2006-11-11 20:52 ` Martin Jambon 2006-11-11 20:59 ` Anastasia Gornostaeva 0 siblings, 2 replies; 8+ messages in thread From: Peter Gregory @ 2006-11-11 20:35 UTC (permalink / raw) Cc: caml-list, ermine Anastasia Gornostaeva wrote: > Hello. > > $ ocaml > Objective Caml version 3.09.3 > > # open Printf;; > # printf "%2$d %1$s" "abc" 2;; > Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' > > > How? > > ermine > Hi Ermine, I'm not sure that I understand your question. I think to achieve what you seem to be trying, you would simply write: # printf "%d %s" 2 "abc";; You just put the parameters in the order they came in the string. Does that help, it seems like perhaps you needed more than that. Regards, Peter. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 20:35 ` [Caml-list] " Peter Gregory @ 2006-11-11 20:52 ` Martin Jambon 2006-11-11 21:15 ` Peter Gregory 2006-11-11 20:59 ` Anastasia Gornostaeva 1 sibling, 1 reply; 8+ messages in thread From: Martin Jambon @ 2006-11-11 20:52 UTC (permalink / raw) To: Peter Gregory; +Cc: ermine, caml-list On Sat, 11 Nov 2006, Peter Gregory wrote: > Anastasia Gornostaeva wrote: >> Hello. >> >> $ ocaml >> Objective Caml version 3.09.3 >> >> # open Printf;; >> # printf "%2$d %1$s" "abc" 2;; >> Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' >> >> >> How? >> >> ermine >> > > Hi Ermine, > > I'm not sure that I understand your question. I think to achieve what you > seem to be trying, you would simply write: > > # printf "%d %s" 2 "abc";; > > You just put the parameters in the order they came in the string. Does that > help, it seems like perhaps you needed more than that. The dollar stuff is real, although I have no idea of how to make it work. It's the last paragraph in the description of Printf.fprintf: http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html Martin -- Martin Jambon, PhD http://martin.jambon.free.fr ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 20:52 ` Martin Jambon @ 2006-11-11 21:15 ` Peter Gregory 2006-11-11 21:26 ` Martin Jambon 2006-11-11 21:40 ` Anastasia Gornostaeva 0 siblings, 2 replies; 8+ messages in thread From: Peter Gregory @ 2006-11-11 21:15 UTC (permalink / raw) To: Martin Jambon; +Cc: Peter Gregory, ermine, caml-list Martin Jambon wrote: > On Sat, 11 Nov 2006, Peter Gregory wrote: > >> Anastasia Gornostaeva wrote: >>> Hello. >>> >>> $ ocaml >>> Objective Caml version 3.09.3 >>> >>> # open Printf;; >>> # printf "%2$d %1$s" "abc" 2;; >>> Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' >>> >>> >>> How? >>> >>> ermine >>> >> >> Hi Ermine, >> >> I'm not sure that I understand your question. I think to achieve what >> you seem to be trying, you would simply write: >> >> # printf "%d %s" 2 "abc";; >> >> You just put the parameters in the order they came in the string. >> Does that help, it seems like perhaps you needed more than that. > > The dollar stuff is real, although I have no idea of how to make it > work. It's the last paragraph in the description of Printf.fprintf: > http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html > > I take a different reading to you Martin, although I think it is confusing. I believe that the number specified before the dollar sign is the argument that specifies the /precision/ of the output. So, it is not to specify the argument to print, but the argument to use as precision. That said, I tried it in the context they suggest and I couldn't make it work! Ermine: do you have a situation where this is important? I can't think of any situation that comes to mind. Peter. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 21:15 ` Peter Gregory @ 2006-11-11 21:26 ` Martin Jambon 2006-11-11 21:40 ` Anastasia Gornostaeva 1 sibling, 0 replies; 8+ messages in thread From: Martin Jambon @ 2006-11-11 21:26 UTC (permalink / raw) To: Peter Gregory; +Cc: ermine, caml-list On Sat, 11 Nov 2006, Peter Gregory wrote: > Martin Jambon wrote: >> On Sat, 11 Nov 2006, Peter Gregory wrote: >> >>> Anastasia Gornostaeva wrote: >>>> Hello. >>>> >>>> $ ocaml >>>> Objective Caml version 3.09.3 >>>> >>>> # open Printf;; >>>> # printf "%2$d %1$s" "abc" 2;; >>>> Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' >>>> >>>> >>>> How? >>>> >>>> ermine >>>> >>> >>> Hi Ermine, >>> >>> I'm not sure that I understand your question. I think to achieve what you >>> seem to be trying, you would simply write: >>> >>> # printf "%d %s" 2 "abc";; >>> >>> You just put the parameters in the order they came in the string. Does >>> that help, it seems like perhaps you needed more than that. >> >> The dollar stuff is real, although I have no idea of how to make it work. >> It's the last paragraph in the description of Printf.fprintf: >> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html >> >> > > I take a different reading to you Martin, although I think it is confusing. > I believe that the number specified before the dollar sign is the argument > that specifies the /precision/ of the output. > > So, it is not to specify the argument to print, but the argument to use as > precision. That said, I tried it in the context they suggest and I couldn't > make it work! Here is what I tried: # open Printf;; # let x = 1234.5678;; val x : float = 1234.5678 (* Just for fun *) # printf "%.2f %.*f" x 3 x;; 1234.57 1234.568- : unit = () (* I understand that the following should print "1234.57 1234.57": *) # printf "%.2f %.*1$f" x x;; Bad conversion %1, at char number 5 in format string ``%.2f %.*1$f'' Martin -- Martin Jambon, PhD http://martin.jambon.free.fr ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 21:15 ` Peter Gregory 2006-11-11 21:26 ` Martin Jambon @ 2006-11-11 21:40 ` Anastasia Gornostaeva 2006-11-12 0:46 ` Martin Jambon 1 sibling, 1 reply; 8+ messages in thread From: Anastasia Gornostaeva @ 2006-11-11 21:40 UTC (permalink / raw) To: Peter Gregory; +Cc: caml-list On Sat, Nov 11, 2006 at 09:15:37PM +0000, Peter Gregory wrote: > I take a different reading to you Martin, although I think it is > confusing. I believe that the number specified before the dollar sign > is the argument that specifies the /precision/ of the output. > > So, it is not to specify the argument to print, but the argument to use > as precision. That said, I tried it in the context they suggest and I > couldn't make it work! > > Ermine: do you have a situation where this is important? I can't think > of any situation that comes to mind. For example: http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC18 In fact I have my own module for translations and i'm interesting in this printf's feature. P.s. Yes, I know about ocaml-gettext library. ermine ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 21:40 ` Anastasia Gornostaeva @ 2006-11-12 0:46 ` Martin Jambon 0 siblings, 0 replies; 8+ messages in thread From: Martin Jambon @ 2006-11-12 0:46 UTC (permalink / raw) To: Anastasia Gornostaeva; +Cc: Peter Gregory, caml-list On Sun, 12 Nov 2006, Anastasia Gornostaeva wrote: > On Sat, Nov 11, 2006 at 09:15:37PM +0000, Peter Gregory wrote: > >> I take a different reading to you Martin, although I think it is >> confusing. I believe that the number specified before the dollar sign >> is the argument that specifies the /precision/ of the output. >> >> So, it is not to specify the argument to print, but the argument to use >> as precision. That said, I tried it in the context they suggest and I >> couldn't make it work! >> >> Ermine: do you have a situation where this is important? I can't think >> of any situation that comes to mind. > > For example: > http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#SEC18 > > In fact I have my own module for translations and i'm interesting in this > printf's feature. OK, so you really want to invert the order of the arguments :-) You might want to use a syntax extension like xstrp4 or heredoc. http://www.ocaml-programming.de/packages/documentation/xstrp4/ http://www.eleves.ens.fr/home/frisch/info/HereDoc.html Martin -- Martin Jambon, PhD http://martin.jambon.free.fr ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] printf and positional specifier 2006-11-11 20:35 ` [Caml-list] " Peter Gregory 2006-11-11 20:52 ` Martin Jambon @ 2006-11-11 20:59 ` Anastasia Gornostaeva 1 sibling, 0 replies; 8+ messages in thread From: Anastasia Gornostaeva @ 2006-11-11 20:59 UTC (permalink / raw) To: Peter Gregory; +Cc: caml-list On Sat, Nov 11, 2006 at 08:35:56PM +0000, Peter Gregory wrote: > ># printf "%2$d %1$s" "abc" 2;; > >Bad conversion %$, at char number 0 in format string ``%2$d %1$s'' > I'm not sure that I understand your question. I think to achieve what > you seem to be trying, you would simply write: > > # printf "%d %s" 2 "abc";; > > You just put the parameters in the order they came in the string. Does > that help, it seems like perhaps you needed more than that. >From documentation on Printf module: Conversion specifications have the following form: % [positional specifier] [flags] [width] [.precision] type The optional positional specifier consists of an integer followed by a $; the integer indicates which argument to use, the first argument being denoted by 1. ermine ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-11-12 0:46 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2006-11-11 20:12 printf and positional specifier Anastasia Gornostaeva 2006-11-11 20:35 ` [Caml-list] " Peter Gregory 2006-11-11 20:52 ` Martin Jambon 2006-11-11 21:15 ` Peter Gregory 2006-11-11 21:26 ` Martin Jambon 2006-11-11 21:40 ` Anastasia Gornostaeva 2006-11-12 0:46 ` Martin Jambon 2006-11-11 20:59 ` Anastasia Gornostaeva
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox