[erlang-bugs] lack of symmetry in format string for fwrite() and fread()
Raimo Niskanen
raimo+erlang-bugs@REDACTED
Wed Apr 30 12:14:04 CEST 2008
On Wed, Apr 23, 2008 at 01:55:11PM +0200, Bengt Kleberg wrote:
> Greetings,
>
> ~b is missing in fread() format string and ~d is missing in fwrite()
> format string.
>
> Although properly documented I still feel that this is a bug in the
> handling of integers in the format string for fwrite() and fread().
>
io_lib:fread("~16b", " -17 ")
-> {ok,[-23]," "}
would then be functionally equivalent to the existing:
io_lib:fread" ~-~16u", " -17 ")
-> {ok,[-1,23]," "}
that delivers the result in two variables, and
io_lib:fread("~b", " -17 ")
-> {ok,[-17]," "}
would then be the same as
io_lib:fread("~d", " -17 ")
-> {ok,[-17]," "}
io:fwrite("~d\n", [-17])
would then be the same as the existing:
io:fwrite("~b\n", [-17])
which actually is a shorthand for:
io:fwrite("~.10b\n", [-17])
So the missing read ~b and write ~d does not add
any functionality, we regard it as a low priority problem.
Do not count on them being added in the near future.
> Exmaple:
> > io:fwrite( "~b", [1]).
> 1
> > io:fwrite( "~d", [1]).
> ** exception exit: {badarg,[{io,format,[<0.30.0>,"~d",[1]]},
> {erl_eval,do_apply,5},
> {shell,exprs,6},
> {shell,eval_exprs,6},
> {shell,eval_loop,3}]}
> in function io:o_request/2
>
> > io_lib:fread( "~d", "1").
> {ok,[1],[]}
> > io_lib:fread( "~b", "1").
> {error,{fread,format}}
>
>
>
> bengt
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-bugs
mailing list