<div dir="ltr"><div dir="ltr">Hi,<div><br></div><div>With the help of <a href="https://github.com/eryx67/erlando.git">https://github.com/eryx67/erlando.git</a>, you can write this as:</div><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">-compile({parse_transform, do}).</font></div><div><font face="monospace">-compile({parse_transform, cut}).</font></div></blockquote><div><font face="monospace"><br></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="monospace">get_nas_from_conf() -></font></div><div><font face="monospace"> do([error_m ||</font></div><div><font face="monospace"> Server <- get_radius_host(),</font></div><div><font face="monospace"> Port <- get_radius_port(),</font></div><div><font face="monospace"> Secret <- get_radius_secret(),</font></div><div><font face="monospace"> return({Server, Port, Secret})</font></div><div><font face="monospace"> ]).</font></div></blockquote><div><br></div><div>This will return {ok, {Server, Port, Secret}} or {error, Error}.</div><div><br></div><div>Regards,<br></div><div>Andreas</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Sa., 18. Sept. 2021 um 22:50 Uhr schrieb Gian Lorenzo Meocci <<a href="mailto:glmeocci@gmail.com">glmeocci@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div>I have a function like this:</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(220,220,170)">get_nas_from_conf</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_host</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_port</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">case</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,170)">get_radius_secret</span><span style="color:rgb(212,212,212)">() </span><span style="color:rgb(197,134,192)">of</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">} -></span></div><div><span style="color:rgb(212,212,212)"> {</span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">};</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">;</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">.</span></div></div></div></div><div><br></div><div>Which is the best way to write this kind of function?</div><div><br></div><div>I'd like to have a with operator like in Elixir, to rewrite my function in this way:</div><div><br></div><div><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:"Fira Code","Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(220,220,170)">get_nas_from_conf</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> <span style="color:rgb(212,212,212)"></span><span style="color:rgb(197,134,192)">with</span> {ok, </span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">} <- </span><span style="color:rgb(220,220,170)">get_radius_host</span><span style="color:rgb(212,212,212)">(),</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(220,220,170)">get_radius_port</span><span style="color:rgb(212,212,212)">(),</span></div><div><span style="color:rgb(212,212,212)"> {ok, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(220,220,170)">get_radius_secret</span><span style="color:rgb(212,212,212)">() -></span></div><div><span style="color:rgb(212,212,212)"> {</span><span style="color:rgb(156,220,254)">Server</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Port</span><span style="color:rgb(212,212,212)">, </span><span style="color:rgb(156,220,254)">Secret</span><span style="color:rgb(212,212,212)">};</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">catch</span></div><div><span style="color:rgb(212,212,212)"> {error, </span><span style="color:rgb(156,220,254)">_Reason</span><span style="color:rgb(212,212,212)">} = </span><span style="color:rgb(156,220,254)">E</span><span style="color:rgb(212,212,212)"> -></span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(156,220,254)">E</span></div><div><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(197,134,192)">end</span><span style="color:rgb(212,212,212)">.</span></div></div></div><div><br></div><div>Any suggestion?</div><div><br></div><div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div>GL<br><a href="https://meox.github.io" target="_blank">https://www.meocci.it</a><br></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><p><span style="font-family:verdana,geneva,sans-serif;font-size:10pt">Andreas Schultz</span></p></div></div>