Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006429OCamlstandard librarypublic2014-05-17 07:472017-02-16 14:01
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target VersionundecidedFixed in Version 
Summary0006429: A format specifier for bytes
DescriptionWithout 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").
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
gasche (developer)
2014-05-17 07:59

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.
whitequark (developer)
2014-05-17 08:03

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.
gasche (developer)
2014-05-17 08:32

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.
doligez (administrator)
2014-05-21 17:31

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.
gasche (developer)
2014-09-21 16:12

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.
doligez (administrator)
2015-02-25 23:37

I think the parallel with %s/%S is quite natural, so if you want to implement only one, it should be %Y...
whitequark (developer)
2016-04-21 11:13

I think implementing just %Y is a good idea.

- Issue History
Date Modified Username Field Change
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 / +beta1
2015-12-09 21:29 xleroy Severity minor => feature
2016-04-21 11:10 doligez Target Version 4.03.0+dev / +beta1 =>
2016-04-21 11:13 whitequark Note Added: 0015836
2016-04-21 12:39 gasche Target Version => 4.03.1+dev
2017-02-16 14:01 doligez Target Version 4.03.1+dev => undecided
2017-02-23 16:43 doligez Category OCaml standard library => standard library

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker