[erlang-questions] Erlang 3000?
Håkan Stenholm
hokan.stenholm@REDACTED
Mon Nov 17 01:44:26 CET 2008
damien morton wrote:
>
>
> On Mon, Nov 17, 2008 at 8:48 AM, mats cronqvist <masse@REDACTED
> <mailto:masse@REDACTED>> wrote:
>
> "Robert Virding" <rvirding@REDACTED <mailto:rvirding@REDACTED>>
> writes:
>
> > Why do you want/need an undef or nil object in language where
> everything has a
> > value? And where you have immutable data?
>
>
> None, True, False are just atoms in Python -
> nothing particularly special about them except the conventions for
> their use.
>
>
> > Many complain about the if *expression* but I don't really
> understand why it
> > warrants so much interest. I personally find that I don't use it
> much anyway,
> > and that because I don't *need* to use it.
>
> you don't use it because it's cruft, and people complain about it
> because they dislike cruft.
>
>
> Right, and its cruft because it raises questions about which should be
> used in which circumstance. Most people will just ignore the "if"
> statement and use a "case" statement instead, but a novice will take a
> while to settle into that usage, always wondering if they should use
> one or the other.
>
> A rough grep through the erlang libraries produces some stats:
>
> 38 thousand "case" statements
> 1800 "if" statements.
>
> So here's a question: Are there any examples of "if" statements that
> would be awkward or difficult to express using a "case" statement?
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.
Yes I know that this could be written as:
to_upper_char(C) when is_integer(C) ->
case ($a =< C andaslo C =< $z) orelse
(16#E0 =< C andalso C =< 16#F6) orelse
(16#F8 =< C andalso C =< 16#FE) of
true -> C - 32;
false -> C
end.
but lets assume that each branch needs to do something different, so we
must either use nested cases or have multiple function clauses (one for
each condition) to check all the guards.
"if"s tend to be convenient in numerical code - like checking for
multiple numeric ranges (as above) or to avoid silly things like:
case .... of
_ when ... -> ...
_ when ... -> ...
_ when ... -> ...
...
end
instead of:
if
... -> ...
... -> ...
... -> ...
...
end
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list