S is defined in the context of that function call, you then<br>do log_message(), and in the new function call S does <br>not exist, it needs to be passed in<br><br><div class="gmail_quote">2009/4/2 Gamoto <span dir="ltr"><gamoto@bluewin.ch></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div class="gmail_quote">I don't understand. After the reception of the filename
the variable S is defined ! </div>
<div class="gmail_quote">I could understand a run-time error if I send a message
before to send the filename !!</div><div><div></div><div class="h5">
<div class="gmail_quote"> </div>
<div class="gmail_quote">2009/4/2 Gamoto <span dir="ltr"><gamoto@bluewin.ch></span><br></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">What
is wrong in this function ? I receive the following error: variable 'S' is
unbound !<br>I also receive two warnings: File is unused, S is unused.<br>This
process can receive two messages: one file to open and one message to
write<br><br>Pid ! {open,"filetoopen.txt"}<br><br>Pid ! {data,
Message}<br><br>log_message()-><br> receive<br>
{open,File} -> case
file:open("File", [append]) of<br>
{ok,S} -> log_message();<br>
{error,Reason} -> io:format( "~s~n",[Reason])<br>
end;<br>
{data,Data} ->
io:format(S,"~s~n",[Data]),<br>
log_message()<br>
end.</blockquote>
<div class="gmail_quote"><br>- The variable File is defined in the message
{file,File} you recieve but is never used, you open the file "File".<br><br>-
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.<br><br>Robert<br><br></div></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br>