[erlang-questions] [RFC] smarter receive

Roger Larsson roger.larsson@REDACTED
Fri Nov 10 16:06:38 CET 2006


On Friday 10 November 2006 04:14, Jay Nelson wrote:
> I wasn't sure that this message was about "proposal to enhance message
> receive"
> because the thread name changed.  You quoted a book I never mentioned and
> then had code that looked very similar to mine.  I assume this is
> somehow related
> and will try to answer.

Yes, it is another proposal.

>
>  > Why not remember this position for next time?
>  > Since the test is constant none of the already scanned messages will
>
> match
>
>  > next time either!
>
> This only helps in the case of constant data.  If there is a variable
> that could change because it is a loop argument or the result of
> another receive, then you must resort back to the full scanning method.  
> This would solve the problem in some cases, but not all, while making
> the implementation more complex. 

I know - I wrote that too :-)

OK, lets try to simplify as much as possible, what is the most common case?

I would guess it is: Tuple with first element a constant atom.
(It would be quite easy to rewrite code in this way... easier than rewriting 
code to match your proposal anyway)

Each receive statement needs to save a pointer to how far in the queue
it has searched or each match could cache the same info. Any receive with
a match all would not need to save anything.

>
>>  - - -
>
> You don't want to change the fundamental semantics of receive in that
> messages are scanned from earliest to latest, and that the order of pattern 
> clauses in a receive statement matters
I never intended to change the semantics. Implementation could change... 

/RogerL



More information about the erlang-questions mailing list