<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="">Well on the first example, there are no guards. I pretty much doubt that there is an illegal guard expression there :P<div class=""><br class=""></div><div class="">But the code was poorly written, I grant you that. I fixed it (and i actually checked that it compiled this time):</div><div class=""><br class=""></div><div class=""><div class="">is_fraction(X) -> lists:member(X, "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒").</div><div class=""><br class=""></div><div class="">is_fraction_with_guards(X) when $¼ =< X, X =< $¾ -> true;</div><div class="">is_fraction_with_guards(X) when $⅐ =< X, X =< $⅞ -> true;</div><div class="">is_fraction_with_guards(_) -> false.</div></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 10:12, Florent Gallaire <<a href="mailto:fgallaire@gmail.com" class="">fgallaire@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Hello Brujo,</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Thanks for your answer.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Why not just…<br class=""><br class="">is_fraction(X) -> lists:member(X, "½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅐⅛⅜⅝⅞⅑⅒”).<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Because it's not possible: "illegal guard expression".</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Or, if you really really want to use function clause heads, pattern-matching and guards:<br class=""><br class="">is_fraction(X) when $¼ =< X =< $¾ -> true;<br class="">is_fraction(X) when $⅐ =< X <= $⅞ -> true;<br class="">is_fraction(_) -> false.<br class=""><br class="">For these kinds of character manipulation things, using the fact that they’re just integers under-the-hood is not a bad idea.<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Yes you're right in this case, but it remains a trick so most of the</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">time it's not applicable.</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Cheers</span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Menlo-Regular; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Cheers!<br class=""><br class="">________________________________<br class="">Brujo Benavides<br class=""><br class=""><br class=""><br class="">On 25 Mar 2019, at 09:38, Florent Gallaire <<a href="mailto:fgallaire@gmail.com" class="">fgallaire@gmail.com</a>> wrote:<br class=""><br class="">Hello Richard,<br class=""><br class="">Thanks for your answer.<br class=""><br 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=""><br class=""><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="">We really need an actual concrete example of real code to discuss.<br class=""><br class=""><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="">On Mon, 25 Mar 2019 at 18:12, Florent Gallaire <<a href="mailto:fgallaire@gmail.com" class="">fgallaire@gmail.com</a>> wrote:<br class=""><br class=""><br class="">Frank thanks for your answer.<br class=""><br class="">You’re probably new to Erlang.<br class=""><br class=""><br class="">Yes, but...<br class=""><br 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=""><br class=""><br class="">...I can say parse_transform is not the solution Erlang needs.<br class=""><br class="">There’s no point to add new syntax to the language.<br class=""><br class=""><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="">/Frank<br class=""><br 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="">erlang-questions@erlang.org<br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""><br class=""><br class=""><br class=""><br class="">--<br class="">FLOSS Engineer & Lawyer<br class="">_______________________________________________<br class="">erlang-questions mailing list<br class="">erlang-questions@erlang.org<br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""><br class=""><br class=""><br class=""><br class="">--<br class="">FLOSS Engineer & Lawyer<br class="">_______________________________________________<br class="">erlang-questions mailing list<br class="">erlang-questions@erlang.org<br class="">http://erlang.org/mailman/listinfo/erlang-questions<br class=""><br class=""><br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">FLOSS Engineer & Lawyer</span></div></blockquote></div><br class=""></div></body></html>