[erlang-questions] pattern match test operator

Vlad Dumitrescu vladdu55@REDACTED
Mon Nov 19 22:15:18 CET 2007


On Nov 16, 2007 10:44 PM, Andras Georgy Bekes <bekesa@REDACTED> wrote:
> case Expr1 of
>    PATTERN1 ->
>       case Expr_with_side_effects of

Yes, when there are side-effects, then my suggestion doesn't work.

But I wonder if it's a ggod idea to put side effects in a match... I
prefer to put them in well lit and guarded places, so that they can't
sneak on my when I'm looking somewhere else :-)

> I've seen a code fragment (in AXD301) several weeks ago, so I can't
> remember correctly, but: The function was supposed to select the first
> case if one argument looked like "R7A..." or "R12C...".
> This could be done with my construct:
> function(X) when ?MATCH("R7A"++_,X) or ?MATCH("R12C"++_,X) ->
>   complicated_function_body().
> All the solutions we've found were ugly in some way.

 function("R7A"++_) ->
 function("R12C"++_) ->

function_aux() ->

is not really ugly, just a little more verbose. I see your point, I
guess that it's a matter of being used with a style and not being as
sensitive to such ugliness.

best regards,

More information about the erlang-questions mailing list