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

Ulf Wiger ulf.wiger@REDACTED
Sat Apr 17 22:59:46 CEST 2004


On Fri, 16 Apr 2004 19:48:40 -0700, Jay Nelson <jay@REDACTED> wrote:

> At 08:19 PM 4/16/04 +0200, Ulf Wiger wrote:
>
>> ... is how how I would write it.  (:
>>
>> validate_colors({R, G, B}) ->
>>    VC = fun(C) -> validate_color(C) end,
>>    {VC(R), VC(G), VC(B)}.
>>
>> validate_color(C) when is_integer(C), C > 0, C < 255 ->
>>    C.
>
> I assume you intended another clause for the non-valid
> cases to avoid the program failing with bad_match:
>
> validate_color(_) ->
>      0.

Actually, no, but I was aware of the fact that by doing so,
I changed the semantics of the code.

I usually don't silently transform illegal input to default
values, especially not in early versions. I find that it is
almost always better to let the program fail in those
cases. And function_clause is a perfectly good way to fail,
IMHO.  (:

/Uffe
-- 
Ulf Wiger




More information about the erlang-questions mailing list