[erlang-questions] 回复: How to make a short circuit in erlang ?

饕餮 <>
Tue Mar 26 03:59:26 CET 2013


My teammate also say I should try to write more function.
It sounds good!
And I also hear Erlang don't have any way to return immediately.  
I have some idea to refact it now, thanks!


------------------ 原始邮件 ------------------
发件人: "Bob Ippolito"<>;
发送时间: 2013年3月26日(星期二) 上午10:54
收件人: "饕餮"<>; 
抄送: "erlang-questions"<>; 
主题: Re: [erlang-questions] How to make a short circuit in erlang ?



There general strategy is to use more functions or have a flat case on a tuple of comparisons (if that can be done sensibly). You could also use exceptions for flow control, but then you have two problems :) 
On Monday, March 25, 2013, 饕餮 <> wrote:
When in other language.We can use like:
 example(Something){
    if( Something == false)
        return;
    //do something here;
}
But in Erlang.I have to write like:
 example(Something) ->
    if
        Something == false ->
             false;
        true ->
            %do something here
     end.




That's could make the multiple nested like:
 example(Something) ->
    if
        Something == false ->
             false;
        true ->
            if
                Otherthing == false ->
                     false
                true ->
                    %do something here
     end.


Some code could make 5 or more nested in it.
 Is there any idea to make short circuit to reduce of the nested?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130326/bf0a0272/attachment.html>


More information about the erlang-questions mailing list