[erlang-questions] examples for erlang with joins

Hubert Plociniczak hubert.plociniczak@REDACTED
Tue Mar 10 01:54:45 CET 2009


2009/3/9 Richard O'Keefe <ok@REDACTED>

>
> On 10 Mar 2009, at 2:08 am, Hubert Plociniczak wrote:
>
>  Message {test, test1, test2} is first in the message. foo is second.
>> Similarly as in original receive I take the newest message and check if
>> only with this message I can satisfy any of the joins.
>> If that is not possible, then I go the next message and check if any of
>> the joins can be satisfied using the new message (and all previous ones).
>> Since {test, test1, test2} already satisfies one of the joins, then I fire
>> it immediately and do not look at what else is in the message
>> after {test, test1, test2} (though I might obviously look at it in the
>> future, if I have any receive constructs afterwards).
>>
>> I hope that helps.
>>
>
> Actually, it helps to scare me off.
> It reminds me too much of XSLT.
> For one thing, the current receive construct (conceptually)
> always starts its search with the *OLDEST* message, not the
> newest one.
>
> So we have in the mailbox
>   oldest = {test,test1,test2}
>   newest = foo
> and in the matching process, the first thing we hit is
>   _X and foo
> and _X does match the first message that we should look
> at (namely the oldest) and foo does then match the
> remaining message.
>

Ok, I agree I named newest for the oldest. When explaining I always get the
naming the other way around ;)
To satisfy the join I am trying to find the smallest, oldest set of messages
in the mailbox.

When designing the joins I took the same approach as receive, i.e. it takes
the message and consecutively matches it against patterns, step by step.
If it doesn't find any pattern that satisfied the message, then it moves to
the next message and repeats.
I didn't want to change this logic, because the other way would mean to have
a look at *some* (possibly big) snapshot of the mailbox and check if the
first patterns is satisfied. If not, then check another one etc.

But then what happens when new messages arrive? There is no way to ensure
(without limiting the size of the snapshot) that previous pattern (or in my
case join) was not satisfied, as some new message that arrived in the
meantime could satisfy it.

This particular case is tricky, so thanks for pointing that out. But I think
it still is correct, because in reality, without joins, it is the second
case (namely _X) that would get satisfied (not _X and foo) - if you were to
hard-code it using for example nested receives.

hubert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090310/4f0f53ed/attachment.htm>


More information about the erlang-questions mailing list