enums anyone?

Mats Cronqvist mats.cronqvist@REDACTED
Fri Aug 4 18:04:46 CEST 2006


   in my quixotic crusade against the use of macros, i've come up against this 
idiom;

-define(TRUE,true).
-define(FALSE,false).
-define(PREF_SILLY_CONSTANT,silly_constant).
-define(PREF_DUMB_CONSTANT, dumb_constant).
-define(PREF_ULTRA_LAME,ultra_lame).

x() ->
   receive
     ?TRUE -> ...
     ?FALSE -> ...
   end.

   as far as i can tell it's to get the compiler to catch typos like "flase" for 
"false".

   so perhaps a language addition like this would be useful.

-enum(BOOL,[true,false]).

x() ->
   receive
     #BOOL.true -> ...;
     #BOOL.false -> ...
   end.

or perhaps

x() ->
   receive
     #BOOL.X -> ...;
     X -> exit(bad_message)
   end.

   the choice of "#" is probably dumb. the "#BOOL.true" would of course be 
transformed to 'true' by the compiler.

   mats

-- 
Premature optimization is the root of all evil in programming.
C. A. R. Hoare



More information about the erlang-questions mailing list