You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 6176 Reporter:@dbuenzli Assigned to:@gasche Status: closed (set by @xavierleroy on 2015-12-11T18:25:47Z) Resolution: fixed Priority: normal Severity: feature Category: standard library Monitored by:@gasche@jmeber@dbuenzli
Bug description
One of the annoyance of the Format module is that if you define a pretty printer pp_v for your value you can use it with Format.fprintf "%a" pp_v v but not directly with Format.sprintf "%a" pp_v v.
Usually I work around by having a to_string function generated from my pp_v as follows:
let to_string_of_formatter pp v = (* NOT thread safe. *)
Format.fprintf Format.str_formatter "%a" pp v;
Format.flush_str_formatter ()
And then do a Format.sprintf "%s" (to_string v).
However it would be simpler to have a function Format.spp, defined as follows:
let spp pp_v () v = (* NOT thread safe. *)
Format.fprintf Format.str_formatter "%a" pp_v v;
Format.flush_str_formatter ()
That would allow to write Format.sprintf "%a" (Format.spp pp_v) v
P.S. Maybe Format.spp should not use Format.str_formatter, I was surprised it worked, thought the flush would trip the Format.sprintf.
The text was updated successfully, but these errors were encountered:
Thanks to commit faf9cb4 by Pierre Weiss which wasn't mentioned in the release notes, I happily discovered that this issue is now fixed in 4.01.0 by using Format.asprintf.
Thanks to commit faf9cb4 by Pierre Weiss which wasn't mentioned in the release notes, I happily discovered that this issue is now fixed in 4.01.0 by using Format.asprintf.
Good catch! Indeed I missed this change when preparing the release notes, as I started from the CHANGES which Pierre forgot to update alongside this commit.
Original bug ID: 6176
Reporter: @dbuenzli
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2015-12-11T18:25:47Z)
Resolution: fixed
Priority: normal
Severity: feature
Category: standard library
Monitored by: @gasche @jmeber @dbuenzli
Bug description
One of the annoyance of the Format module is that if you define a pretty printer pp_v for your value you can use it with Format.fprintf "%a" pp_v v but not directly with Format.sprintf "%a" pp_v v.
Usually I work around by having a to_string function generated from my pp_v as follows:
let to_string_of_formatter pp v = (* NOT thread safe. *)
Format.fprintf Format.str_formatter "%a" pp v;
Format.flush_str_formatter ()
And then do a Format.sprintf "%s" (to_string v).
However it would be simpler to have a function Format.spp, defined as follows:
let spp pp_v () v = (* NOT thread safe. *)
Format.fprintf Format.str_formatter "%a" pp_v v;
Format.flush_str_formatter ()
That would allow to write Format.sprintf "%a" (Format.spp pp_v) v
P.S. Maybe Format.spp should not use Format.str_formatter, I was surprised it worked, thought the flush would trip the Format.sprintf.
The text was updated successfully, but these errors were encountered: