<div dir="ltr">Hi Viktor,<div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Viktor Söderqvist <<a href="mailto:viktor@zuiderkwast.se">viktor@zuiderkwast.se</a>> schrieb am Sa., 16. Feb. 2019 um 19:24 Uhr:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey list!<br>
<br>
Last night I was thinking that it might be possible to implement<br>
if-elseif-else syntax using macros and a parse transform, so you can<br>
write like this:<br>
<br>
-include_lib("elseif/include/elseif.hrl").<br>
<br>
f(X) -><br>
?'if'(X > 0) -> pos<br>
?elseif(X < 0) -> neg<br>
?else -> zero<br>
end.<br></blockquote><div><br></div><div>but why would you use such a thing when you can simply write:</div><div><br></div><div><font face="monospace">if X > 0 -> pos;</font></div><div><font face="monospace"> X < 0 -> neg;</font></div><div><font face="monospace"> true -> zero</font></div><div><font face="monospace">end.</font></div><div><br></div><div>Andreas</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
It's possible. Here is how: <a href="https://github.com/zuiderkwast/elseif" rel="noreferrer" target="_blank">https://github.com/zuiderkwast/elseif</a><br>
<br>
Disclaimer: This may be considered macro and parse-transform abuse. You<br>
may get strange syntax error messages if e.g. using ?elseif without<br>
?'if' or if leaving out the mandatory ?else part.<br>
<br>
Viktor<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span style="font-family:monospace,monospace">-- <br>Dipl.-Inform. Andreas Schultz<br><br>----------------------- enabling your networks ----------------------<br>Travelping GmbH Phone: +49-391-81 90 99 0<br>Roentgenstr. 13 Fax: +49-391-81 90 99 299<br>39108 Magdeburg Email: <a href="mailto:info@travelping.com">info@travelping.com</a><br>GERMANY Web: <a href="http://www.travelping.com">http://www.travelping.com</a><br><br></span><div><span style="font-family:monospace,monospace">Company Registration: Amtsgericht Stendal Reg No.: HRB 10578</span></div><span style="font-family:monospace,monospace">Geschaeftsfuehrer: Holger Winkelmann VAT ID No.: DE236673780<br>---------------------------------------------------------------------</span></div></div>