Three IO library related problems

matthias <>
Thu Aug 30 00:41:14 CEST 2001


Matthias wrote
 > >In R7B-3:
 > >
 > >	18> io_lib:fread("~d.~d", "22").            
 > >	
 > >	=ERROR REPORT==== 2-Aug-2001::21:37:53 ===
 > >	ERROR: "Error in process <0.54.0> with exit value: 
 > >	{function_clause,[{io_lib_fread,fread,[\".~d\",[],2,[22]]},
 > >	{erl_eval,expr,3},{erl_eval,exprs,4},{shell,eval_loop,2}]}\n" 
 > >	** exited: {function_clause,[{io_lib_fread,fread,[".~d",[],2,[22]]},
 > >	                             {erl_eval,expr,3},
 > >	                             {erl_eval,exprs,4},
 > >	                             {shell,eval_loop,2}]} **
 > >
 > >I think it should return {more, ....}. 

Robert wrote
 > No, this is perfectly correct.  io_lib:fread/2 takes a format string
 > and an input string and tries to extract ALL the specified fields.  It
 > is not re-entrant!

If it's not intended to be re-entrant, why does fread/2 return {more, ...}
in some cases? Consider these two cases:

  io_lib:fread("~d.~d", "22")        crashes the process (function_clause)
  io_lib:fread("~d~d", "22")         returns {more,"~d",2,[22]}

If this is perfectly correct, then (a) how can I guess whether the
fread/2 is going to crash or return {more, ...} for a particular input
which only satisfies part of the format string and (b) why is it
crashing with function_clause as a reason instead of badarg?

 > >On a related note, it'd be nice if the man page/web page for io_lib
 > >said that the {more, ....} tuple returned from fread/2 can be used as
 > >a continuation for fread/3. 

 > If the manual implies that io_lib:fread/2 is the initial re-entrant
 > call then it is wrong.

When io_lib:fread/2 returns {more, ...}, it's returning something
which looks like a continuation for io_lib:fread/3, but isn't. With
some re-shuffling and wrapping it can be (ab)used as a "clayton's
continuation" for fread/2. My mistaken inference.

Matthias



More information about the erlang-questions mailing list