|Anonymous | Login | Signup for a new account||2015-10-13 20:30 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006429||OCaml||OCaml standard library||public||2014-05-17 07:47||2015-07-10 18:48|
|Priority||normal||Severity||minor||Reproducibility||have not tried|
|Target Version||4.03.0+dev||Fixed in Version|
|Summary||0006429: A format specifier for bytes|
|Description||Without a %S-like format specifier for Bytes, debugging becomes extremely annoying--the code is littered with bogus conversions everywhere. Perhaps it's possible to provide one?|
It also makes sense to provide its non-escaped equivalent as well ("%s").
|Tags||No tags attached.|
|I have no idea of what a good syntax would be. My only idea would be to reuse "%#s" (currently considered as "%s", but planning-to-be-outlawed in 4.02 as it doesn't mean anything), and it's mediocre at best.|
|Well, you could disambiguate the conflict with %b/%B by using the second letter: %y/%Y, in the same way as e.g. options for Unix tools are disambiguated. This is what I would expect, at least.|
Note that in the meantime, we could make sure that
"%a" Bytes.print by
"%a" Bytes.to_string by
works (by adding the relevant functions if need be for some *printf function), which would already have reasonable readability.
While we decide which letter to use, you should use this for debugging without too much pain:
let (!!) = Bytes.unsafe_to_string;;
Printf.printf "hello %s\n" !!my_byte_sequence;;
For the letter, I think Y is a good candidate. My first idea was Z but we might want to use that for bignums at some point in the future.
As for %#s, that would make the type depend on the format's flags rather than the letter. A very bad idea.
I considered implementing this, but I'm not happy with having both %y and %Y.
The problem is that the usual semantics of the big-letter version is "as written in OCaml source code", so it would seem natural that whichever output syntax is chosen for %Y also produces valid OCaml literals; but we have no literal syntax for bytes.
On the other hand, the escaped-printing behavior of %S is certainly more useful than the non-escaped behavior of %s for bytes, for the "byte sequences" applications that have no reason to stay in the printable ASCII range; so if we had only one formatter for bytes, it should probably have the semantics of %S.
|I think the parallel with %s/%S is quite natural, so if you want to implement only one, it should be %Y...|
|2014-05-17 07:47||whitequark||New Issue|
|2014-05-17 07:59||gasche||Note Added: 0011510|
|2014-05-17 08:03||whitequark||Note Added: 0011511|
|2014-05-17 08:32||gasche||Note Added: 0011512|
|2014-05-21 17:31||doligez||Note Added: 0011536|
|2014-05-21 17:32||doligez||Status||new => confirmed|
|2014-05-21 17:32||doligez||Target Version||=> 4.02.0+dev|
|2014-08-18 18:22||doligez||Target Version||4.02.0+dev => 4.02.1+dev|
|2014-09-04 00:25||doligez||Target Version||4.02.1+dev => undecided|
|2014-09-15 21:29||doligez||Target Version||undecided => 4.02.2+dev / +rc1|
|2014-09-21 16:12||gasche||Note Added: 0012180|
|2015-02-25 23:37||doligez||Note Added: 0013346|
|2015-03-18 17:58||frisch||Target Version||4.02.2+dev / +rc1 => 4.02.3+dev|
|2015-07-10 18:48||doligez||Target Version||4.02.3+dev => 4.03.0+dev|
|Copyright © 2000 - 2011 MantisBT Group|