[erlang-questions] Erlang 3000?

Richard O'Keefe ok@REDACTED
Thu Nov 20 01:29:26 CET 2008


On 19 Nov 2008, at 10:33 pm, Johnny Billquist wrote:

> Richard O'Keefe wrote:
>> On 17 Nov 2008, at 1:44 pm, Håkan Stenholm wrote:
>>> Conditionals that have more than 2 branches where none of them   
>>> branch on
>>> patterns - e.g. something like the to_upper code below:
>>>
>>> to_upper_char(C) when is_integer(C) ->
>>> if
>>>    $a =< C, C =< $z       -> C - 32;
>>>    16#E0 =< C, C =< 16#F6 -> C - 32;
>>>    16#F8 =< C, C =< 16#FE -> C - 32;
>>>    true -> C
>>> end.
>> If this is supposed to convert ISO Latin 1 characters
>> to upper case, it's wrong.  (In at least two different
>> ways, both of which are left as an exercise for the
>> reader.)  Code for such purposes simply shouldn't be
>> written by hand these days, but should be generated by
>> some sort of script from the (relevant portion of the)
>> Unicode data base.  As such, whether it's written using
>> 'case', 'if', or embedded Intercal should be of no interest.
>
> ??? That's a perfectly correct translation from lowercase to  
> uppercase for Latin-1.

But it doesn't check that the input *is* Latin 1.
(One of the two mistakes I thought I saw was a mistake
on my part, but that one's real.)
to_upper_char(-137) => -137, for example.
The last clause would be better as

	0 =< C, C =< 16#FF -> C

As a matter of fact, I'd expect a fair bit of "Latin 1"
these days to be really Latin 9 or Windows-whatsit,
both of which have extra letters.  Latin 9 has an upper case
version of 16rFF (at 16rBE).  My machine has oodles of 8859-15
locales...




More information about the erlang-questions mailing list