[erlang-questions] Problem running code from Armstrong's Programming Erlang

Michael McDaniel erlangx@REDACTED
Sat Jun 16 20:21:47 CEST 2007


On Sat, Jun 16, 2007 at 09:56:16AM -0400, David Cabana wrote:
> I am reading a beta copy of Joe Armstrong's "Programming Erlang."   
> The book's support site provides code samples for download; I have a
> question regarding a pair of similar bits of code from the site. One 

 <snip>
   
> and am trying to understand what is going wrong. The code is  
> available at http://media.pragprog.com/titles/jaerlang/code/ 
> ctemplate.erl
> %% --------------- begin second example
> 
> -module(ctemplate).
> -compile(export_all).
> 
> start() ->
>      spawn(fun() -> loop([]) end).
> 
> rpc(Pid, Request) ->
>      Pid ! {self(), Request},
>      receive
> 	{Pid, Response} ->
> 	    Response
>      end.
> 	
> loop(X) ->
>      receive
> 	Any ->
> 	    io:format("Received:~p~n",[Any]),
> 	    loop(X)
>      end.
> 
> %% --------------- end second example
> 
> Notice that the second example is very similar to the first. It's  
> purpose is to provide some scaffolding into which the user can  
> interactively insert new messages and message handling code.  When I  
> try to use it, my session hangs. Here's the terminal session,  
> starting with a new erl session.
> 
> %% --------------- begin second example behavior
> 
> Eshell V5.5.4  (abort with ^G)
> 1> c(ctemplate).
> {ok,ctemplate}
> 
> 2> Pid = ctemplate:start().
> <0.38.0>
> 
> 3> ctemplate:rpc(Pid, {foo}).
> Received:{<0.31.0>,{foo}}
> 
> %% --------------- end second example behavior
> 
> The erl session hangs at that point. I suspect user error, but have  
> no clue what the error might be. I'm brand new to Erlang, and would  
> much appreciate any insight on what's going wrong here. Thank you.
> 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 note that the rpc/2 fun is sending a message back to the
 Pid used as first arg.
 try ...

 3> ctemplate:rpc( self(), {foo}).
 {foo}


~Michael

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us




More information about the erlang-questions mailing list