[erlang-questions] Issue with "Programming Erlang" sample
John Williston
jwilliston@REDACTED
Tue Apr 16 14:52:11 CEST 2013
Good morning,
I'm learning Erlang using the Programming Erlang (2d ed) text from
Pragmatic Bookshelf. Chapter two, "A Whirlwind Tour of Erlang" includes
a file server sample that's failing to work as the book suggests, and
I'm afraid I'm not getting anywhere figuring it out. First, here's the
server code:
-module(afile_server).
-export([start/1]).
start(Dir) -> spawn(afile_server, loop, [Dir]).
loop(Dir) ->
receive
{Client, list_dir} ->
Client ! {self(), file:list_dir(Dir)};
{Client, {get_file, File}} ->
Full = filename:join(Dir, File),
Client ! {self(), file:read_file(Full)}
end,
loop(Dir).
That compiles (albeit with a warning saying "Warning: function loop/1 is
unused") but when I try to execute it from within the shell I get an
error. For sake of reference the shell commands I'm issuing are:
Eshell V5.10.1 (abort with ^G)
1> c(afile_server).
afile_server.erl:7: Warning: function loop/1 is unused
{ok,afile_server}
2> FileServer = afile_server:start(".").
<0.39.0>
3>
=ERROR REPORT==== 10-Apr-2013::10:31:17 ===
Error in process <0.39.0> with exit value:
{undef,[{afile_server,loop,["."],[]}]}
Can anyone suggest what might be wrong? I'm running under Windows 7
Professional x64 for sake of reference. Thanks in advance!
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130416/8ede5609/attachment.htm>
More information about the erlang-questions
mailing list