<div dir="ltr">Hi,<div><br></div><div>Your receive for interact function is trying to match Pid along with Response:</div><div><br></div><div><br style="font-size:12.8px"><span style="font-size:12.8px">interact(Pid, Request) -></span><br style="font-size:12.8px"><span style="font-size:12.8px">  Pid ! {self(), Request},</span><br style="font-size:12.8px"><span style="font-size:12.8px">  receive</span><br style="font-size:12.8px"><span style="font-size:12.8px">    <b>{Pid, Response} -> Response</b></span><br style="font-size:12.8px"><span style="font-size:12.8px">  end.</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">loop(Table) -></span><br style="font-size:12.8px"><span style="font-size:12.8px">  receive</span><br style="font-size:12.8px"><span style="font-size:12.8px">    {From, {insert, key, value}} -></span><br style="font-size:12.8px"><span style="font-size:12.8px">      From ! ets:insert(Table, {Key, Value}),  %% << you are not sending something to match with Pid</span><br style="font-size:12.8px"><span style="font-size:12.8px">      loop(Table);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    {From, {lookup, key}} -></span><br style="font-size:12.8px"><span style="font-size:12.8px">      From ! ets:lookup(Table, Key), </span><span style="font-size:12.8px">%% << you are not sending something to match with Pid</span><br style="font-size:12.8px"><span style="font-size:12.8px">      loop(Table);</span><br style="font-size:12.8px"><span style="font-size:12.8px">    Any -></span><br style="font-size:12.8px"><span style="font-size:12.8px">      Any</span><br style="font-size:12.8px"><span style="font-size:12.8px">  end.</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">So I think this correct send code should be: </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">From ! {<b>self(),</b> ets:insert(Table, {Key, Value})}</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">and</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">From ! {<b>self(), </b>ets:lookup(Table, Key)},</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks,</span></div><div><span style="font-size:12.8px">Pravin</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 15, 2016 at 1:28 PM, Pietro <span dir="ltr"><<a href="mailto:pulsarpietro@posteo.net" target="_blank">pulsarpietro@posteo.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><a href="mailto:dmkolesnikov@gmail.com">dmkolesnikov@gmail.com</a> writes:<br>
<br>
> Hello,<br>
><br>
> You are using atoms instead of variables in your program. Erlang<br>
> variables starts with capital letter.<br>
><br>
> The receive loop cannot match your message:<br>
><br>
>Â Â Â {From, {insert, key, value}} -><br>
><br>
> It expects one triple of atoms but you send different one.<br>
><br>
>Â Â Â test:interact(Pid, {insert, testkey, testvalue}).<br>
><br>
> Dmitry<br>
><br>
> Sent from my iPhone<br>
</span>Ouch ! Thank you very much, I knew I were missing something crucial<br>
here, would you help me in my next step ?<br>
<br>
loop(Table) -><br>
  receive<br>
    {From, {insert, Key, Value}} -><br>
      io:format("Here insert"),<br>
      Return = ets:insert(Table, {Key, Value}),<br>
      From ! Return,<br>
      loop(Table);<br>
    {From, {lookup, Key}} -><br>
      io:format("Here lookup"),<br>
      Return = ets:lookup(Table, Key),<br>
      From ! Return,<br>
      loop(Table);<br>
    {From, Any} -><br>
      From ! {self(), {error,Any}},<br>
      loop(Table)<br>
  end.<br>
<br>
This code results in :<br>
<br>
1> c(test).<br>
{ok,test}<br>
2> Pid = test:start().<br>
<0.40.0><br>
3> Pid ! {self(), {insert, a, 1}}.<br>
Here insert{<0.33.0>,{insert,a,1}}<br>
4> Pid ! {self(), {lookup, a}}.<br>
Here lookup{<0.33.0>,{lookup,a}}<br>
<br>
<br>
It does not return the the stored values even though it clearly matches<br>
the patterns, where is the rub here ?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
><br>
> On 15 Mar 2016, at 00:53, Pietro <<a href="mailto:pulsarpietro@posteo.net">pulsarpietro@posteo.net</a>> wrote:<br>
><br>
>Â Â Â Hi all,<br>
><br>
>Â Â Â I have recently started to implement a small academic project in<br>
>Â Â Â Erlang<br>
>Â Â Â and I have bumped into a problem which seems to show to myself I<br>
>Â Â Â haven't<br>
>Â Â Â grasped something important about the technology itself.<br>
><br>
>Â Â Â That's my code :<br>
><br>
>Â Â Â -module(test).<br>
>Â Â Â -export([start/0, interact/2]).<br>
><br>
><br>
>Â Â Â start() -><br>
>Â Â Â spawn (fun() -> startloop() end).<br>
><br>
><br>
>Â Â Â interact(Pid, Request) -><br>
>Â Â Â Pid ! {self(), Request},<br>
>Â Â Â receive<br>
>Â Â Â {Pid, Response} -> Response<br>
>Â Â Â end.<br>
><br>
><br>
>Â Â Â startloop() -><br>
>Â Â Â TableId = ets:new(dictionary, [set]),<br>
>Â Â Â loop(TableId).<br>
><br>
>Â Â Â loop(Table) -><br>
>Â Â Â receive<br>
>Â Â Â {From, {insert, key, value}} -><br>
>Â Â Â From ! ets:insert(Table, {key, value}),<br>
>Â Â Â loop(Table);<br>
>Â Â Â {From, {lookup, key}} -><br>
>Â Â Â From ! ets:lookup(Table, key),<br>
>Â Â Â loop(Table);<br>
>Â Â Â Any -><br>
>Â Â Â Any<br>
><br>
>Â Â Â end.<br>
><br>
><br>
>Â Â Â The problem happens when I try to interact with the server I start<br>
>Â Â Â using<br>
>Â Â Â the command:<br>
><br>
>Â Â Â Pid = test:start().<br>
><br>
>Â Â Â Then I run :<br>
><br>
>Â Â Â test:interact(Pid, {insert, testkey, testvalue}).<br>
><br>
>Â Â Â My ershell at this point hangs and nothing happens ... what is<br>
>Â Â Â happening<br>
>Â Â Â ? Please feel free to redirect me to a more appropriate newsgroup<br>
>Â Â Â if my<br>
>Â Â Â question is not appropriate or if there is a better one.<br>
><br>
>Â Â Â Thanks in advance.<br>
><br>
>Â Â Â Pietro.<br>
><br>
>Â Â Â _______________________________________________<br>
>Â Â Â erlang-questions mailing list<br>
>Â Â Â <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>Â Â Â <a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>