[erlang-questions] variable unbound

Richard Carlsson richardc@REDACTED
Thu Apr 2 15:24:10 CEST 2009


Gamoto wrote:
> I don't understand. After the reception of the filename the variable S is defined ! 
> I could understand a run-time error if I send a message before to send the filename !!
> 
> 2009/4/2 Gamoto <gamoto@REDACTED>
> 
> What is wrong in this function ? I receive the following error: variable 'S' is unbound !
> I also receive two warnings: File is unused, S is unused.
> This process can receive two messages: one file to open and one message to write
> 
> Pid ! {open,"filetoopen.txt"}
> 
> Pid ! {data, Message}
> 
> log_message()->
>   receive
>     {open,File} -> case file:open("File", [append]) of
                                    ^^^^^^^
                                    don't put File inside quotes

>                      {ok,S} ->  log_message();
                           ^
                           this S is not used

>                      {error,Reason} -> io:format( "~s~n",[Reason])
>                    end;
>     {data,Data} -> io:format(S, "~s~n", [Data]),
                               ^^
                               S is not bound to anything here

>                    log_message()
>   end.

    /Richard



More information about the erlang-questions mailing list