[erlang-questions] variable unbound

Gamoto gamoto@REDACTED
Thu Apr 2 14:57:34 CEST 2009

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}

               {open,File} -> case file:open("File", [append]) of
                                                       {ok,S} ->  log_message();
                                   {error,Reason} -> io:format( "~s~n",[Reason])
               {data,Data} ->  io:format(S,"~s~n",[Data]),

- The variable File is defined in the message {file,File} you recieve but is never used, you open the file "File".

- The variable S is defined when you receive the {open,File} message, but you wish to use it when you receive the {data,Data} message where it is not defined.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090402/72e1ad01/attachment.htm>

More information about the erlang-questions mailing list