<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Via <a href="http://learnyousomeerlang.com/syntax-in-functions">LYSE</a> and ROK - and with the forlorn hope that this doesn't start up again :-)  --> </div><div><br></div><div><p style="margin: 0px 0px 13px; color: rgb(86, 86, 86); ">It may be more FAMILIAR, but that doesn't mean 'else' is a good thing. I know that writing '; true ->' is a very easy way to get 'else' in Erlang, but we have a couple of decades of psychology-of-programming results to show that it's a bad idea. I have started to replace:</p><div style="margin: 0px; color: rgb(86, 86, 86); ">                          by</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">   </span>if X > Y -> a()<span class="Apple-tab-span" style="white-space:pre">               </span>if X > Y  -> a()</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">  </span> ; true  -> b()<span class="Apple-tab-span" style="white-space:pre">             </span> ; X =< Y -> b()</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">       </span>end<span class="Apple-tab-span" style="white-space:pre">         </span>     <span class="Apple-tab-span" style="white-space:pre">     </span>end</div><div style="margin: 0px; color: rgb(86, 86, 86); min-height: 14px; "><br></div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">       </span>if X > Y -> a()<span class="Apple-tab-span" style="white-space:pre">               </span>if X > Y -> a()</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">        </span> ; X < Y -> b()<span class="Apple-tab-span" style="white-space:pre">               </span> ; X < Y -> b()</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">        </span> ; true  -> c()<span class="Apple-tab-span" style="white-space:pre">             </span> ; X ==Y -> c()</div><div style="margin: 0px; color: rgb(86, 86, 86); "><span class="Apple-tab-span" style="white-space:pre">   </span>end<span class="Apple-tab-span" style="white-space:pre">                 </span>end</div><p style="margin: 0px; color: rgb(86, 86, 86); min-height: 14px; "><span class="Apple-tab-span" style="white-space:pre">  </span><br class="webkit-block-placeholder"></p><p style="margin: 0px 0px 13px; color: rgb(86, 86, 86); ">which I find mildly annoying when _writing_ the code but enormously helpful when _reading_ it.</p></div>Speaking for myself, I've pretty much gotten to the point where I don't notice it.  <div>Heck, I barely notice syntax anymore.  About the best analogy I can come up with is spoken languages (adjectives <i>after</i> nouns in Italian? The Horror! The Horror!).  It may seem strange at first, but you don't even notice it after a few days…</div><div><br></div><div>Cheers</div><div><br></div><div><br><div>
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="margin: 0in 0in 0.0001pt; "><font class="Apple-style-span" color="#1f497d" face="Calibri, sans-serif"><span class="Apple-style-span" style="font-size: 15px; "><b><i><div style="margin: 0px; font-style: normal; font-weight: normal; font-family: Calibri; "><a href="http://www.gravatar.com/avatar/204a87f81a0d9764c1f3364f53e8facf.png"><b><i>Mahesh Paolini-Subramanya</i></b></a></div></i></b></span></font></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); ">That Tall Bald Indian Guy...</span></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; "><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125); "><div style="margin: 0px; font-family: Calibri; color: rgb(1, 108, 226); "><span style="text-decoration: underline; "><a href="https://plus.google.com/u/0/108074935470209044442/posts">Google+</a></span><span style="color: rgb(31, 73, 125); ">  | <a href="http://dieswaytoofast.blogspot.com/"><span style="color: rgb(1, 108, 226); ">Blog</span></a></span><span style="text-decoration: underline; "> </span><span style="color: rgb(31, 73, 125); ">  | <span style="color: rgb(1, 108, 226); "><a href="https://twitter.com/dieswaytoofast">Twitter</a></span></span><span style="color: rgb(31, 73, 125); ">  | </span><a href="http://www.linkedin.com/in/dieswaytoofast">LinkedIn</a></div></span></div></div>
</div>
<br><div><div>On Jun 15, 2013, at 2:40 AM, Steve Davis <<a href="mailto:steven.charles.davis@gmail.com">steven.charles.davis@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I strongly (personally) dislike use of "if" syntax, but only because of the counterintuitive "true" evaluation.<div><br></div><div>What if the language were to return the atom "else" instead of "true"?</div><div><br></div><div>I doubt that would be considered "better" but it would sure make things more readable...</div><div><br></div><div>/s<br><br>On Friday, June 14, 2013 8:06:33 AM UTC-5, Lars Herbach wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">



<div style="word-wrap:break-word">
Hi List,
<div>I'm currently working myself through the "Études for Erlang" book [1] and in exercise it wks's to write a recursive function, calculating the greatest common divisor for two numbers N and M. The suggested solution is a single gcd/2 function with an If
 condition and recursion:</div>
<div><br>
</div>
<div><font face="Courier New">gcd(M, N) -> </font></div>
<div><font face="Courier New">    if M == N -> M;</font></div>
<div><font face="Courier New">       M > N -> gcd(M - N, N;</font></div>
<div><font face="Courier New">       true -> gcd(M, N - M)</font></div>
<div><font face="Courier New">    end.</font></div>
<div><font face="Courier"><br>
</font></div>
<div>I by myself took another way, working with multiple function clauses (did I name it right?):</div>
<div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New">gcd(M, N) when M == N -></font></div>
<div><font face="Courier New">    M;</font></div>
<div><font face="Courier New">gcd(M, N) when M > N -></font></div>
<div><font face="Courier New">    gcd(M - N, N);</font></div>
<div><font face="Courier New">gcd(M, N) -></font></div>
<div><font face="Courier New">    gcd(M,  N - M).</font></div>
</div>
<div><font face="Courier New"><br>
</font></div>
<div>Now I've got two questions about that: </div>
<div>1) Is my solution still recursive, since I practically call different functions?</div>
<div>2) Are there any benefits in regards of efficiancy for the first solution?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Lars.</div>
<div><br>
</div>
<div><br>
</div>
<div>[1]: <a href="http://shop.oreilly.com/product/0636920030034.do" target="_blank">http://shop.oreilly.com/<wbr>product/0636920030034.do</a></div>
</div>

</blockquote></div>_______________________________________________<br>erlang-questions mailing list<br><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>http://erlang.org/mailman/listinfo/erlang-questions<br></blockquote></div><br></div></body></html>