[erlang-questions] case and pattern matching
Tue Jul 10 12:41:40 CEST 2007
You can use guards as below :
init_indecies(Tab, Storage, PosList) ->
case Storage of
S when S==unknown;S==s3_copies ->
S when S==ram_copies;S==disc_copies ->
You're forced to bind a variable and I also sometimes wish there was a
shorter way of writing it too.
Joel Reymont a écrit :
> What do you do when two clauses in your case statement need to share
> the code? Do you create an anonymous function and reuse it?
> I really wish there was a way to combine patterns but I can't seem to
> find any. Consider the following bit of Mnesia code:
> init_indecies(Tab, Storage, PosList) ->
> case Storage of
> unknown ->
> s3_copies ->
> disc_only_copies ->
> init_disc_index(Tab, PosList);
> ram_copies ->
> make_ram_index(Tab, PosList);
> disc_copies ->
> make_ram_index(Tab, PosList)
> What I would like to do is join unknown and s3_copies or maybe
> ram_copies and disc_copies in a single pattern match like
> uknown | s3_copies -> ...
> Is this possible?
> Thanks, Joel
> http://topdog.cc - EasyLanguage to C# compiler
> http://wagerlabs.com - Blog
> erlang-questions mailing list
More information about the erlang-questions