[erlang-questions] pattern match test operator

Vlad Dumitrescu vladdu55@REDACTED
Mon Nov 19 22:02:03 CET 2007


Hi!

On Nov 19, 2007 1:45 PM, Andras Georgy Bekes <bekesa@REDACTED> wrote:
> What if you want to filter a list or query a database with two patterns?
> You don't (yet) want to retreive the internal terms, just want to have
> the elements matching certain patterns.
>
> Instead of writing
>
> [ X || X <- ListOrQLCTable
>         case X of
>            PATTERN1 ->
>               true;
>            PATTERN2 ->
>               true;
>            _ ->
>               false
>         end]
>
> You could write this (assume ~= the pattern-match-test operator):
>
>
> [ X || X <- ListOrQLCTable,
>         PATTERN1 ~= X orelse PATTERN2 ~= X]
>
> Isn't it nicer?

Absolutely nicer!

What I feel is that such a notation isn't bringing enough to the
language so that it's worth it.

If pattern1 and pattern2 above are wildly different, then I'm not sure
what the meaning would be for the resulting list. If they are similar,
but some sub-terms are different, then I would better like to see a
regexp-like syntax for terms matching. Of course, for that it is much
more difficult to find an appropriate syntax...

regards,
Vlad



More information about the erlang-questions mailing list