exported variables (was: RE: How to make GS Widgets)
Tony Rogvall
tony@REDACTED
Sat Apr 17 23:52:28 CEST 2004
lördagen den 17 april 2004 kl 22.59 skrev Ulf Wiger:
> 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.
>
Why add an extra "named" function ? Why not ?
validate_colors({R, G, B}) ->
VC = fun(C) -> when C>=0, C=<255 -> C end,
{VC(R), VC(G), VC(B)}.
My guess is that is that R/G/B should be valid in the range [0,255] !
Note that I still think my version is the most elegant :-) (and
efficient)
/Tony
More information about the erlang-questions
mailing list