[erlang-questions] Idiom for multiple case matches
Kevin Scaldeferri
kevin@REDACTED
Mon Nov 10 19:44:52 CET 2008
On Nov 9, 2008, at 3:06 PM, mats cronqvist wrote:
> Michael Radford <mrad-direct-erlang@REDACTED> writes:
>
>> I hesitate to wade into this cranky-fest, but IMO this is extremely
>> clear and easy to read:
>>
>> is_vowel ($a) -> true;
>> is_vowel ($e) -> true;
>> is_vowel ($i) -> true;
>> is_vowel ($o) -> true;
>> is_vowel ($u) -> true;
>> is_vowel (_) -> false.
>>
>> That's just saying directly what you mean in a language that's nice
>> enough to make it reasonably efficient.
>
> and what you mean is presumably that 'is_vowel' is a function that
> returns 'true' if its argument is a member of the list "aeiou",
> otherwise 'false'.
>
> the fact that this is a fairly common task is of course the reason
> why lists:member/2 exists in the first place. so by not using
> lists:member/2 here, you are obfuscating the fact that you are
> indeed testing if something is a member of a list.
Well, if you want to be pedantic, that's completely wrong. There's
nothing list-like about the collection of vowels. It's a set. So,
clearly, in the interest of clarity, we should use set:member/2, even
though that's orders of magnitude slower.
> and the style of cut-and-paste programming you use is also bad. for
> example, it's easy to get lost in the paste-fest and forget that "y"
> is a vowel.
I've been watching this discussion waiting for someone to point out
the glaring problem with this whole exercise, which is that "vowel-
ness" is language-dependent. So, in that sense, all approaches which
have been presented so far are wrong.
-kevin
More information about the erlang-questions
mailing list