[erlang-questions] case and pattern matching

Joel Reymont joelr1@REDACTED
Tue Jul 10 12:08:31 CEST 2007


Folks,

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 ->
	    ignore;
	s3_copies ->
	    ignore;
	disc_only_copies ->
	    init_disc_index(Tab, PosList);
	ram_copies ->
	    make_ram_index(Tab, PosList);
	disc_copies ->
	    make_ram_index(Tab, PosList)
     end.

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








More information about the erlang-questions mailing list