[erlang-questions] file:read_line - conflicting return values' syntax - no case clause matching eof exception

Kostis Sagonas <>
Mon Feb 15 09:24:17 CET 2010


Kay Kay wrote:
> As per the documentation here -
> 
> http://ftp.sunet.se/pub/lang/erlang/doc/man/file.html#read_line-1  ,
> the syntax reads as -
> 
> read_line(IoDevice) -> {ok, Data} | eof | {error, Reason}
> 
> Given the ambiguity in the return values of the function , I am unsure 
> how to handle it.

Ambiguity?  Which ambiguity?

The return values {ok, Data} and {error, Reason} are pairs (2-tuples) 
which are distinguished by a different atom in the 1st position.  The 
third return value is an *atom*.  Do not wrap it in { } and make it a 
one-element tuple instead...

Kostis

> do_read_file(IoDevice, InData, Accum) ->
>   case file:read_line(IoDevice) of
>     {'ok', Data}  ->
>       do_read_file(IoDevice, Data, lists:append(Accum, InData));
>     { 'eof' } ->
>       Accum
>    end.
> 
> 
> I wrote this function to use the same, but I am getting - "** exception 
> error: no case clause matching eof" .
> 
> What is the best way to handle the same ?




More information about the erlang-questions mailing list