<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hey Florent,<div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>Why not just…</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>is_fraction(X) -> lists:member(X, "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒”).</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Or, if you really really want to use function clause heads, pattern-matching and guards:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>is_fraction(X) when $¼ =< X =< $¾ -> true;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">     </span>is_fraction(X) when $⅐ =< X <= $⅞ -> true;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>is_fraction(_) -> false.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>For these kinds of character manipulation things, using the fact that they’re just integers under-the-hood is not a bad idea.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">    </span>Cheers!</div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><span id="docs-internal-guid-e691a4cc-056a-0210-b8b7-ea8d87d888ad" class=""><span style="font-size: 11pt; font-family: Arial; font-weight: 700; font-variant-ligatures: normal; font-variant-position: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;" class=""><br class="Apple-interchange-newline"><hr class=""></span></span><div class=""><b class=""><i class=""><a href="http://about.me/elbrujohalcon" class="">Brujo Benavides</a></i></b></div></div></div><div style="color: rgb(0, 0, 0); font-family: 'Trebuchet MS'; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><b class=""><br class=""></b></div><br class="Apple-interchange-newline">
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 25 Mar 2019, at 09:38, Florent Gallaire <<a href="mailto:fgallaire@gmail.com" class="">fgallaire@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello Richard,<br class=""><br class="">Thanks for your answer.<br class=""><br class=""><blockquote type="cite" class="">lists:member(X, [X1,X2,X3,X4]) answers true or false.<br class="">There is no fundamental reason that the compiler could not<br class="">expand that in-line to (X =:= X1 orselse ... orelse X =:= X4)<br class="">when the shape of the list is known.  So we *definitely* need<br class="">no new syntax.<br class=""></blockquote><br class="">So if there's no reason the compiler could not do it, we *really*<br class="">should have a new syntax.<br class=""><br class=""><blockquote type="cite" class="">We really need an actual concrete example of real code to discuss.<br class=""></blockquote><br class="">The developed version of the is_fraction/1 function:<br class=""><br class="">is_fraction($½) -> true;<br class="">is_fraction($⅓) -> true;<br class="">is_fraction($⅔) -> true;<br class="">is_fraction($¼) -> true;<br class="">is_fraction($¾) -> true;<br class="">is_fraction($⅕) -> true;<br class="">is_fraction($⅖) -> true;<br class="">is_fraction($⅗) -> true;<br class="">is_fraction($⅘) -> true;<br class="">is_fraction($⅙) -> true;<br class="">is_fraction($⅚) -> true;<br class="">is_fraction($⅐) -> true;<br class="">is_fraction($⅛) -> true;<br class="">is_fraction($⅜) -> true;<br class="">is_fraction($⅝) -> true;<br class="">is_fraction($⅞) -> true;<br class="">is_fraction($⅑) -> true;<br class="">is_fraction($⅒) -> true;<br class="">is_fraction(_) -> false.<br class=""><br class="">The awful actual "with a guard" version:<br class=""><br class="">is_fraction(X) when X =:= $½; X =:= $⅓; X =:= $⅔; X =:= $¼; X =:= $¾;<br class="">X =:= $⅕; X =:= $⅖; X =:= $⅗; X =:= $⅘; X =:= $⅙; X =:= $⅚; X =:= $⅐;<br class="">X =:= $⅛; X =:= $⅜; X =:= $⅝; X =:= $⅞; X =:= $⅑; X =:= $⅒ -> true;<br class="">is_fraction(_) -> false.<br class=""><br class="">The pretty, easy and obviously needed "with in list syntactic sugar" version :<br class=""><br class="">is_fraction(X) when X in "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒" -> true;<br class="">is_fraction(_) -> false.<br class=""><br class="">It clearly speaks for itself.<br class=""><br class="">Cheers.<br class=""><br class=""><blockquote type="cite" class="">On Mon, 25 Mar 2019 at 18:12, Florent Gallaire <<a href="mailto:fgallaire@gmail.com" class="">fgallaire@gmail.com</a>> wrote:<br class=""><blockquote type="cite" class=""><br class="">Frank thanks for your answer.<br class=""><br class=""><blockquote type="cite" class="">You’re probably new to Erlang.<br class=""></blockquote><br class="">Yes, but...<br class=""><br class=""><blockquote type="cite" class="">You can achieve the same with parse_transform:<br class=""><a href="https://github.com/mad-cocktail/gin/blob/master/README.rst" class="">https://github.com/mad-cocktail/gin/blob/master/README.rst</a><br class=""></blockquote><br class="">...I can say parse_transform is not the solution Erlang needs.<br class=""><br class=""><blockquote type="cite" class="">There’s no point to add new syntax to the language.<br class=""></blockquote><br class="">Yes we need it, an easy to use built-in "in (tuple or list I'm not<br class="">sure of the right semantic)" syntactic sugar for guards.<br class=""><br class="">Hope some other advices.<br class=""><br class="">Florent<br class=""><br class=""><blockquote type="cite" class="">/Frank<br class=""><br class=""><blockquote type="cite" class="">Hello everybody,<br class=""><br class="">I'm not very experimented in Erlang but I read carefully books and<br class="">official documention.<br class=""><br class="">It seems to me that the guards syntax is not as good as it should be,<br class="">i.e. too much verbose for multiple values.<br class=""><br class="">do(val1) -> val1;<br class="">do(val2) -> val2;<br class="">do(val3) -> val3;<br class="">do(val4) -> val4;<br class="">do(val5) -> val5.<br class=""><br class="">do(Val) when Val =:= val1; Val =:= val2; Val =:= val3; Val =:= val4;<br class="">Val =:= val5 -> Val.<br class=""><br class="">It's boring and error prone to write.<br class=""><br class="">Has a "in tuple" syntax already be considered ? Something like :<br class=""><br class="">do(Val) when Val in {val1, val2, val3, val4, val5} -> Val.<br class=""><br class="">Cheers<br class=""><br class="">Florent<br class=""><br class="">--<br class="">FLOSS Engineer & Lawyer<br class="">_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></blockquote></blockquote><br class=""><br class=""><br class="">--<br class="">FLOSS Engineer & Lawyer<br class="">_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></blockquote></blockquote><br class=""><br class=""><br class="">-- <br class="">FLOSS Engineer & Lawyer<br class="">_______________________________________________<br class="">erlang-questions mailing list<br class=""><a href="mailto:erlang-questions@erlang.org" class="">erlang-questions@erlang.org</a><br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""></div></div></blockquote></div><br class=""></div></body></html>