[erlang-questions] Erlang 3000?
Håkan Stenholm
hokan.stenholm@REDACTED
Wed Nov 19 22:34:38 CET 2008
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.)
Its a slightly modified (and less verbose) version of the code below,
taken from string.erl in R12B-5.
to_upper_char(C) when is_integer(C), $a =< C, C =< $z ->
C - 32;
to_upper_char(C) when is_integer(C), 16#E0 =< C, C =< 16#F6 ->
C - 32;
to_upper_char(C) when is_integer(C), 16#F8 =< C, C =< 16#FE ->
C - 32;
to_upper_char(C) ->
C.
I choose this function because it was a simple example of where a 'if'
is nicer than a 'case' or a guard, not because of any merit (or lack
thereof) of the purpose of the above code itself. Maybe we should get
back to discussing Erlang 3000 in this thread? e.g. could 'if' be
replaced by another construct ... , rather than discussing the nastiness
of unicode and various other text encodings.
> 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.
>
>> case .... of
>> _ when ... -> ...
>> _ when ... -> ...
>> _ when ... -> ...
>> ...
>> end
>
> Did I write up a proposal for
> case ...
> of ... when ... -> ...
> ; when ... -> ...
> ; ...
> ; ... when ... -> ...
> ; when ... -> ...
> ; ...
> ; .......
> end
> or did I just stick it into my radically incomplete micro-Erlang?
>
More information about the erlang-questions
mailing list