<font size="1"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
log_message(File)-></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">  receive</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
     {open,File} -> <br>      case file:open("File", [append]) of</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        {ok,FileD} -> <br>          log_message(FileD);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
         {error,Reason} -> <br>          io:format( "~s~n",[Reason])</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
       end;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
      {data,Data} ->  <br>        case File of <br>          not_open -> <br>            exit(oops_file_not_open);<br>          Else -> <br>           io:format(File,"~s~n",[Data]),</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">
            log_message(File)</span><br>                end<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
   end.</span></font><br>
<br>is closer to what you are wanting, variable only have scope<br>within a function call, this isnt a closure, to keep a variable<br>in scope you pass it into the next call of the function.<br><br><div class="gmail_quote">
2009/4/2 Robert Virding <span dir="ltr"><<a href="mailto:rvirding@gmail.com">rvirding@gmail.com</a>></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 class="gmail_quote">2009/4/2 Gamoto <span dir="ltr"><gamoto@bluewin.ch></span><div class="im"><br><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><div><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>
<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>