Version franaise
Home About Download Resources Contact us

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
precision not working properly for strings in Printf?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-06-27 (09:53)
From: Jonathan Bryant <jtbryant@v...>
Subject: Re: [Caml-list] precision not working properly for strings in Printf?

> I was just expecting it to work like the printf from the glibc:

>>> Any clue why the same convention has
>>> not been followed?

Apparently my implication in my first response was not clear to some,  
so I'll clarify what I meant:

The reasons for not following standard *nix conventions is a choice  
of the language/library designer, so I cannot speak on their behalf.

I'd assume, though, that since the library was implemented from  
scratch, the conventions were not followed because it was, in some  
cases, opportune not to follow them.  For example, some glibc  
conventions do not work for OCaml (such as pointer conversions), and  
the existing conventions did not handle things such as polymorphic  
values.  In these cases, the designer simply took advantage of an  
opportunity to "fix" printf for OCaml.  There's nothing wrong with  
glibc's implementation, except that it's designed for C.

In other cases, such as the string conversion specifier, there is no  
contradiction, so maybe it's an oversight, maybe it's for consistency  
with numeric conversions, maybe it's easier to implement that way, or  
maybe it's just how the designer thought it should work.  In any  
case, that's the way the library was designed and documented and it's  
the designer's prerogative to implement it how they see fit.  The  
OCaml version is only based on glibc's printf while being designed  
specifically for OCaml, probably with the knowledge that String.sub  
is a simple function to use.

In light of the above, I think that unfortunately the answer to the  
question of "why" is actually moot in this case because it is highly  
unlikely to change given that changing it could break existing code  
(in very subtle ways, none the less).

> What about reading before replying ?
> Your "explanation" certainly doesn't answer his question.
> whether or not it's the same *implementation* doesn't answer why ocaml
> printf choosed a different *convention* (specially on this case  
> which I
> don't see any contradiction in the way ocaml works).

I'm sorry if my reply seemed curt and unclear: I was not trying to be  
rude in my response, but only succinct.  I'll try to be clearer in  
the future.


> Cheers,
> -- 
> Vincent Hanquez
> _______________________________________________
> Caml-list mailing list. Subscription management:
> Archives:
> Beginner's list:
> Bug reports: