exported variables (was: RE: How to make GS Widgets)

Cedric Shock cedricpublic@REDACTED
Fri Apr 16 08:22:01 CEST 2004


Richard O'Keefe and Ulf Wiger,

Thank you for your suggestions of improved coding style. This is my 
first week of erlang programming, or even functional programming (I 
started by reading Concurrent Programming in Erlang a week ago). I am 
still strugling through documentation with almost everything I do. I 
like the style

{Red,Green,Blue} = case SuppliedColor of
                         {_,_,_} -> SuppliedColor;
                          _       -> {0,0,0}
                    end

For its brevity and the way it makes the purpose of the code clear. I 
have been bothered by the weekness of my quards, but I do not know how 
to make them stronger. How can I put gaurds on the values of members of 
tuples? For example, I would like the SuppliedColor to be integers in 
the range [0, 255]. How could I write this guard clause? Is this the 
right thing to do?

{Red,Green,Blue} = case SuppliedColor of
                         {TestRed,TestGreen,TestBlue} when
                           is_integer(TestRed),
                           is_integer(TestGreen),
                           is_integer(TestBlue),
                           TestRed =< 255, TestRed => 0,
                           TestGreen =< 255, TestGreen => 0,
                           TestBlue =< 255, TestBlue => 0,  ->
                             SuppliedColor;
                         _ ->
                             {0,0,0}
                    end

Thanks for your input,

Cedric Shock




More information about the erlang-questions mailing list