<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6000.16809" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT size=1>Are you sure this code is correct ?</FONT></DIV>
<DIV><FONT size=1>lines 1 and 16: log_message(FileD) </FONT></DIV>
<DIV><FONT size=1>line 4: open(File, ...)</FONT></DIV>
<DIV><FONT size=1></FONT> </DIV>
<DIV><FONT size=1>But I am newbie ... then correct me if I am wrong ...</DIV>
<DIV><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>
<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="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV class=gmail_quote>2009/4/2 Gamoto <SPAN
dir=ltr><gamoto@bluewin.ch></SPAN>
<DIV class=im><BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">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></BODY></HTML>