[erlang-questions] Side-effects in "if" guards

Per Melin per.melin@REDACTED
Thu May 15 21:18:20 CEST 2008


2008/5/15 Darren New <dnew@REDACTED>:
> Rather than the more straightforward
>   if X is a list andalso string:tolower(X) = X
>     andalso len(X) = 5 andalso true = my:noduplicates(X) -> good;

A check that involved should probably be factored into its own function anyway.

foo(X) ->
    case is_string_ok(X) of
        true -> good;
        false -> bad
    end.

is_string_ok(X) ->
    is_list(X) andalso length(X) == 5 andalso
    string:tolower(X) == X andalso my:no_duplicates(X).



More information about the erlang-questions mailing list