<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>You just need a small proxy process that implements a message dictionary rather than a message queue. The dictionary could even be the processes dictionary. Something like this perhaps (completely untested, and from a relative newbie)</div><div><br></div><div>-module(message_dictionary).</div><div>-export([get/2, start/0, stop/1]).</div><div><br></div><div>start() -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>spawn(fun loop/0). % should probably be spawn_link instead<br></div><div><br></div><div>loop() -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>receive<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{get, From, Tag} -><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>From ! erlang:get(Tag),<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>io:format("Returning message with tag ~p, value ~p and removing from dictionary~n",<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>[Tag, erlang:get(Tag)]),<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>erlang:erase(Tag),<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>loop();<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>stop -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>ok;<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>{Tag, Msg}=M -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>case erlang:put(Tag, Msg) of</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>undefined -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>io:format("Received message ~p; did not replace any old message~n", [M]);</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Old -><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>io:format("Received message ~p; replaced old message ~p~n", [M, Old])<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end,<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>loop();<span class="Apple-tab-span" style="white-space:pre"></span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Other -><span class="Apple-tab-span" style="white-space:pre"></span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>io:format("Received untagged message ~p~n", [Other]),<span class="Apple-tab-span" style="white-space:pre"></span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>loop();<span class="Apple-tab-span" style="white-space:pre"> </span><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end.</div><div><br></div><div>%%% Client functions</div><div><br></div><div>get(Pid, Tag) -></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Pid ! {get, self(), Tag},<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>receive<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>Any -> Any<br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>end.<br></div><div><br></div><div>stop(Pid) -></div><div><div><span class="Apple-tab-span" style="white-space: pre; "> </span>Pid ! stop.<br></div><div><br></div><div><br></div><div>So basically all it does is implement a small process which accepts messages (eg. {msgtag, {some, [structure, of], [[whatever]]}}) and stores this in the processes dictionary, as illustrated with just put and get below:</div><div><br></div><div><div>1> put(foo, bar).</div><div>undefined</div><div>2> put(foo, baz).</div><div>bar</div><div>3> get(foo).</div><div>baz</div><div><br></div><div>Hopefully there are no glaring faults; I'm still reasonably new to designing programs in Erlang myself, perhaps others will help to point out and repair any holes.</div></div><div><br></div></div><div><div><div>On 06/05/2009, at 3:04 AM, Giorgos Kollias wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello Erlang users,<br><br>Is there an option in the Erlang runtime to automatically delete a message that has been deposited into a process's mailbox as soon as a newer message with the same tag arrives? Is it easy to "patch" the Erlang language source code to support this "little" feature in case this is not there?<br> <br>Or the only feasible way of getting this behavior is just to receive all messages till you get a sort of timeout and just keep the latest message with the tag you are interested in (i.e. user code only) in each receive phase? Is there a standard code idiom/snippet for this?<br> <br>This feature would be very interesting for implementing the asynchronous iterations computing paradigm where each process only keeps the most up-to-date message when it looks into its incoming messages. <br><br>Thanks in advance,<br> <br>giorgos<br><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://www.erlang.org/mailman/listinfo/erlang-questions">http://www.erlang.org/mailman/listinfo/erlang-questions</a></blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>-- </div><div>Cameron Kerr <<a href="mailto:ckerr@cs.otago.ac.nz">ckerr@cs.otago.ac.nz</a>></div><div>Teaching Fellow, Computer Science, University of Otago</div><div><font class="Apple-style-span" color="#008000"><br></font></div></div></span></div></span></div></span></div></span></div></span></div></span><br class="Apple-interchange-newline"> </div><br></div></body></html>