[erlang-questions] Pattern-matching function?

anders conbere aconbere@REDACTED
Wed Oct 29 16:18:11 CET 2008


On Wed, Oct 29, 2008 at 7:24 AM, Richard Carlsson <richardc@REDACTED> wrote:
> Francois De Serres wrote:
>> Hi there.
>>
>> I need a function that actually does pattern matching: pm(Tuple, Pattern)->MatchedPattern|error
>
> You cannot pass a pattern with uninstantiated variables to a function.
> Erlang is a strict functional language, it is not Prolog. Patterns are
> not run-time values.

That being said, the lack of first class access to Patterns makes
programmatic access to a few of the most common tools in erlang
exceptionally difficult. Constructing case statements at runtime is
impossible with out accessing the preproccessor, building functions at
runtime that have many different possible patterns, also impossible.
It seems like there should be some way to gain access to this.

I could for instance imagine delaying access to with a function that
accepted something like

pattern(x, supplies("X"), y, z)

which would return a function that when applied to a tuple

{x, anything, y, z}

would return

{ok, {match, [{"X", anything}]}}

and in that way you could construct semantics for applying those to
case statements or function parameters, etc. Maybe that's crazy, but I
sympathize with Francois, I've been trying to fumble my way through
erlang metaprogramming and just running into huge walls like this.

~ Anders




>
>    /Richard
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list