<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span><div style="font-size: 12pt;"><span>Hi,</span></div><div style="background-color: transparent;"><span>maybe this would work?</span></div><div style="font-size: medium; background-color: transparent;"><span>http://en.wikipedia.org/wiki/Higher-order_function<br></span></div><div style="background-color: transparent;"><span><br></span></div><div style="background-color: transparent;"><span></span></div><pre class="de1" style="font-family: monospace, monospace; padding: 0px; border: 0px none white; background-color: rgb(249, 249, 249); line-height: 1.2em; font-size: 13px; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top;"><span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="br0" style="color: rgb(16, 154,
 184);">[</span><span class="br0" style="color: rgb(16, 154, 184);">]</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">_</span><span class="br0" style="color: rgb(16, 154, 184);">)</span> <span class="sy1" style="color: rgb(107, 184, 16);">-></span> <span class="me1" style="color: rgb(0, 102, 0);">false</span><span class="sy1" style="color: rgb(107, 184, 16);">;</span>
<span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="br0" style="color: rgb(16, 154, 184);">[</span><span class="re5" style="color: rgb(69, 179, 230);">F</span> | <span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="br0" style="color: rgb(16, 154, 184);">]</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">X</span><span class="br0" style="color: rgb(16, 154, 184);">)</span> <span class="sy1" style="color: rgb(107, 184, 16);">-></span> <span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">X</span><span class="sy1" style="color: rgb(107, 184,
 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">F</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">X</span><span class="br0" style="color: rgb(16, 154, 184);">)</span><span class="br0" style="color: rgb(16, 154, 184);">)</span><span class="sy1" style="color: rgb(107, 184, 16);">.</span>
 
<span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">X</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> false<span class="br0" style="color: rgb(16, 154, 184);">)</span> <span class="sy1" style="color: rgb(107, 184, 16);">-></span> <span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">X</span><span class="br0" style="color: rgb(16, 154, 184);">)</span><span class="sy1" style="color: rgb(107, 184, 16);">;</span>
<span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">_</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="br0" style="color: rgb(16, 154, 184);">{</span>false<span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">Y</span><span class="br0" style="color: rgb(16, 154, 184);">}</span><span class="br0" style="color: rgb(16, 154, 184);">)</span> <span class="sy1" style="color: rgb(107, 184, 16);">-></span> <span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">Fs</span><span class="sy1" style="color: rgb(107,
 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">Y</span><span class="br0" style="color: rgb(16, 154, 184);">)</span><span class="sy1" style="color: rgb(107, 184, 16);">;</span>
<span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="re5" style="color: rgb(69, 179, 230);">_</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">_</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="re5" style="color: rgb(69, 179, 230);">R</span><span class="br0" style="color: rgb(16, 154, 184);">)</span> <span class="sy1" style="color: rgb(107, 184, 16);">-></span> <span class="re5" style="color: rgb(69, 179, 230);">R</span><span class="sy1" style="color: rgb(107, 184, 16);">.</span>
 
<span class="re3" style="color: rgb(255, 60, 0);">or_else</span><span class="br0" style="color: rgb(16, 154, 184);">(</span><span class="br0" style="color: rgb(16, 154, 184);">[</span><span class="kw1" style="color: rgb(24, 104, 149);">fun</span> <span class="kw5" style="color: rgb(255, 78, 24);">erlang</span>:<span class="kw4" style="color: rgb(250, 111, 255);">is_integer</span><span class="sy3" style="color: rgb(1, 78, 164);">/</span><span class="nu0" style="color: rgb(255, 150, 0);">1</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="kw1" style="color: rgb(24, 104, 149);">fun</span> <span class="kw5" style="color: rgb(255, 78, 24);">erlang</span>:<span class="kw4" style="color: rgb(250, 111, 255);">is_atom</span><span class="sy3" style="color: rgb(1, 78, 164);">/</span><span class="nu0" style="color: rgb(255, 150, 0);">1</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span> <span class="kw1" style="color:
 rgb(24, 104, 149);">fun</span> <span class="kw5" style="color: rgb(255, 78, 24);">erlang</span>:<span class="kw4" style="color: rgb(250, 111, 255);">is_list</span><span class="sy3" style="color: rgb(1, 78, 164);">/</span><span class="nu0" style="color: rgb(255, 150, 0);">1</span><span class="br0" style="color: rgb(16, 154, 184);">]</span><span class="sy1" style="color: rgb(107, 184, 16);">,</span><span class="nu0" style="color: rgb(255, 150, 0);">3.23</span><span class="br0" style="color: rgb(16, 154, 184);">)</span><span class="sy1" style="color: rgb(107, 184, 16);">.</span></pre><pre class="de1" style="font-family: monospace, monospace; padding: 0px; border: 0px none white; background-color: rgb(249, 249, 249); line-height: 1.2em; font-size: 13px; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top;"><span class="sy1" style="color: rgb(107, 184, 16);"><br></span></pre><pre class="de1" style="font-family: monospace,
 monospace; padding: 0px; border: 0px none white; background-color: rgb(249, 249, 249); line-height: 1.2em; font-size: 13px; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top;"><br></pre><pre class="de1" style="font-family: monospace, monospace; padding: 0px; border: 0px none white; background-color: rgb(249, 249, 249); line-height: 1.2em; font-size: 13px; margin-top: 0px; margin-bottom: 0px; background-image: none; vertical-align: top;"><span class="sy1" style="color: rgb(107, 184, 16);"><br></span></pre><div></div><div style="font-size: 12pt;">Johan</div></span></div><div><br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;">  <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <hr
 size="1">  <b><span style="font-weight:bold;">From:</span></b> 饕餮 <249505968@qq.com><br> <b><span style="font-weight: bold;">To:</span></b> erlang-questions <erlang-questions@erlang.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Tuesday, March 26, 2013 3:31 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> [erlang-questions] How to make a short circuit in erlang ?<br> </font> </div> <br>
<div id="yiv1308250311"><div>When in other language.We can use like:</div><div>example(Something){</div><div>    if( Something == false)</div><div>        return;</div><div>    //do something here;</div><div>}</div><div>But in Erlang.I have to write like:</div><div><div style="line-height:16.799999237060547px;"><div style="line-height:16.799999237060547px;">example(Something) -></div><div style="line-height:16.799999237060547px;">    if</div><div style="line-height:16.799999237060547px;">        Something == false -></div><div style="line-height:16.799999237060547px;">            false;</div><div style="line-height:16.799999237060547px;">        true -></div><div style="line-height:16.799999237060547px;">            %do something here</div><div style="line-height:16.799999237060547px;"> 
   end.</div></div></div><div style="line-height:16.799999237060547px;"><br></div><div style="line-height:16.799999237060547px;">That's could make the multiple nested like:</div><div style="line-height:16.799999237060547px;"><div style="line-height:16.799999237060547px;">example(Something) -></div><div style="line-height:16.799999237060547px;">    if</div><div style="line-height:16.799999237060547px;">        Something == false -></div><div style="line-height:16.799999237060547px;">            false;</div><div style="line-height:16.799999237060547px;">        true -></div><div style="line-height:16.799999237060547px;">            if</div><div style="line-height:16.799999237060547px;">                Otherthing == false -></div><div style="line-height:16.799999237060547px;">   
                 false</div><div style="line-height:16.799999237060547px;">                true -></div><div style="line-height:16.799999237060547px;">                    %do something here</div><div style="line-height:16.799999237060547px;">    end.</div><div style="line-height:16.799999237060547px;"><br></div><div style="line-height:16.799999237060547px;">Some code could make 5 or more nested in it.</div><div style="line-height:16.799999237060547px;">Is there any idea to make short circuit to reduce of the nested?</div></div></div><br>_______________________________________________<br>erlang-questions mailing list<br><a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions"
 target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br> </div> </div> </blockquote></div>   </div></body></html>