[eeps] Match specs and receive

Fredrik Linder fredrikelinder@REDACTED
Tue May 6 15:47:03 CEST 2008


Hi

Any chance that something like the following will be implemented in the
Erlang langugage?

function(MatchSpec) ->
   receive
       MatchSpec(Result) ->
            Result
   end.

Result could be a [{var(), value()}] list, where var() somehow is specified
in the given MatchSpec. MatchSpec could as well be "used like a fun";

function(MatchSpec) ->
    receive
        MatchSpec(A, B, C) ->
            [{a, A}, {b, B}, {c, C}]
    end.

I happens every now and then that I write code that is data driven, in a way
where I have a specification and an engine executing this specification. Not
seldom this ends up in me wanting to receive specific messages from the
process queue.

Another use for a "boundable" match spec is in function heads:

function(MatchSpec(Result) = Value, [MatchSpec | T]) ->
   %% something

This too I find lacking in the Erlang language.

It is usually possible to find a workaround for this that is less flexible
and results in a lot more code.

/Fredrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/eeps/attachments/20080506/4163d5a7/attachment.htm>


More information about the eeps mailing list