Higher order receieve anybody

Vlad Dumitrescu <>
Tue Feb 17 17:02:44 CET 2004


----- Original Message ----- 
From: "Joe Armstrong" <>
> What Uffe and Vlad *really* need is a "higher order" receives ...
>
> The idea is to rewrite:
>
> receive
>    {a, X} -> ...
>    b ->
>    Y -> ...
> end
>
> as
>
> F = fun({a,X}) -> ...
>        (b) -> ...
>        (Y) -> ...
>     end,
> Z = receive F,

Hi Joe,

I have a headache today, so I am not sure I understand what you mean (when it
comes to what we discussed before). If you have some time to explain, I wil be
very happy :-)

What we need is to be able to dynamically insert clauses in the fun (or
receive), so that system messages get processed.

If matching incoming messages is done just on F's clauses (i.e. {a, X}, b and
Y), then I don't see any difference from what we have today. If however the
compiler would expand

 G = fun({m,X}) -> ...
        (z) -> ...
        (Y) -> ...
     end,
 F = fun({a,X}) -> ...
        (b) -> ...
        (Y) -> G(Y)
     end,
 receive F,

into something equivalent to

 receive
    {a,X} -> ...
    b -> ...
    {m,X} -> ...
    z -> ...
    Y -> ...
 end,

then I clearly see the point. I think it would work only if G is a fun (or
possibly a local function), because ordinary external functions may change at
runtime and we'd need to recompile dependent modules.

Was it something like this you meant?

best regards,
Vlad




More information about the erlang-questions mailing list