[erlang-questions] Beginner question

Siraaj Khandkar siraaj@REDACTED
Tue Mar 15 06:26:47 CET 2016


On Mar 14, 2016, at 18:53, Pietro <pulsarpietro@REDACTED> wrote:
> 
> Hi all,
> 
> I have recently started to implement a small academic project in Erlang
> and I have bumped into a problem which seems to show to myself I haven't
> grasped something important about the technology itself.
> 
> That's my code :
> 
> -module(test).
> -export([start/0, interact/2]).
> 
> 
> start() ->
>    spawn (fun() -> startloop() end).
> 
> 
> interact(Pid, Request) ->
>    Pid ! {self(), Request},
>    receive 
>    {Pid, Response} -> Response
>    end.
> 
> 
> startloop() ->
>    TableId = ets:new(dictionary, [set]),
>    loop(TableId).
> 
> loop(Table) ->
>    receive
>    {From, {insert, key, value}} ->
>        From ! ets:insert(Table, {key, value}),
>        loop(Table);
>    {From, {lookup, key}} ->
>        From ! ets:lookup(Table, key),
>        loop(Table);
>    Any ->
>        Any
>        
>    end.
> 
> 
> The problem happens when I try to interact with the server I start using
> the command:
> 
> Pid = test:start().
> 
> Then I run :
> 
> test:interact(Pid, {insert, testkey, testvalue}).
> 
> My ershell at this point hangs and nothing happens ... what is happening
> ? Please feel free to redirect me to a more appropriate newsgroup if my
> question is not appropriate or if there is a better one.

interact/2 is waiting for a message structured differently from what loop/1 is sending.


More information about the erlang-questions mailing list