[erlang-questions] pattern match test operator

Vlad Dumitrescu vladdu55@REDACTED
Tue Nov 20 08:54:22 CET 2007


Hi!

On Nov 19, 2007 11:38 PM, Matthew Dempsky <matthew@REDACTED> wrote:
> On 11/19/07, Andras Georgy Bekes <bekesa@REDACTED> wrote:
> > [ X || X <- ListOrQLCTable,
> >         PATTERN1 ~= X orelse PATTERN2 ~= X]
>
> Below you'll find a module that adds a parse transform so you can
> write expressions like '~'(Pattern = X) or match(Pattern = X).
...
>   %% Want to transform Name(Pattern = Body) to case Body of Pattern
>   %% -> true; _ -> false end.

Cool!

Just a note of warning: this implementation "leaks" variables in the
surrounding environment. If you only match against constants, this is
no issue, but if variables are present and subsequently reused, there
may be some unwanted effects.

best regards,
Vlad



More information about the erlang-questions mailing list