<div dir="ltr"><div>This is timely, because we're trying to land EEP-49: <a href="https://github.com/erlang/otp/pull/5216">https://github.com/erlang/otp/pull/5216</a></div><div><br></div><div>Which would turn the original code into:</div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">get_nas_from_conf() -><br></span></div><div><span style="font-family:monospace">
  begin<br></span></div><div><span style="font-family:monospace">
    {ok, Server} <- get_radius_host(),<br>
    {ok, Port} <- get_radius_port(),<br>
    {ok, Secret} <- get_radius_secret(),<br>
    {Server, Port, Secret}</span></div><div><span style="font-family:monospace">  cond</span></div><div><span style="font-family:monospace">    {error, _} = E -> E</span></div><div><span style="font-family:monospace">  end.</span></div><div><br></div><div>The 'cond' keyword is still in the air (the EEP specified 'else' but we hit an implementation snag).<br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 20, 2021 at 5:05 AM Jesper Louis Andersen <<a href="mailto:jesper.louis.andersen@gmail.com">jesper.louis.andersen@gmail.com</a>> wrote:<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 class="gmail_default" style="font-family:arial,helvetica,sans-serif">What about something like:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">get_nas_from_conf() -></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  {ok, Server} = get_radius_host(),</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  {ok, Port} = get_radius_port(),</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  {ok, Secret} = get_radius_secret(),</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">  {Server, Port, Secret}.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Errors are now just crashes. But if the errors are really truly something you want to handle, chances are you need some other flow anyway.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 18, 2021 at 10:50 PM Gian Lorenzo Meocci <<a href="mailto:glmeocci@gmail.com" target="_blank">glmeocci@gmail.com</a>> wrote:<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">J.</div>
</blockquote></div>