First, let me point out that Erlang’s receive primitive is often referred to as a selective receive. (Googling for ’ “selective receive” Erlang’ finds almost 2000 hits.)
I see at least three issues with your proposal:
-
What about guards? Where do they come in? If you’re serious here, you owe me an implementation of
important/1
using yourmessage_select/2
, i.e. what we discussed in this topic. -
And in what way is your proposal any better than using
thread_get_message/1
, like so?:
query(Query, Self, Parent) :-
call_cleanup(Query, Det=true),
( var(Det)
-> Parent ! success(Self, Query, true),
thread_get_message(Message),
(Message==next -> fail;
Message==stop -> Parent ! stopped(Self))
; Parent ! success(Self, Query, false)
).
- And what happens if someone sends a message
foo
to the process, does is crash? Or is the message deferred? Usingthread_get_message/1
as above would not deferfoo
, but since the whole if-then fails, it would have the same effect as sendingnext
. (There are ways around that but you have to change the form of your messages.) What about your solution?