<div dir="ltr">More than a year ago, the OTP team has decided to not remove tuple calls from the language i.e. this is valid Erlang code:<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>({erlang, 1, 2, 3}):is_tuple().</div><div><br></div></blockquote><div>Most times though, such calls are written in the format:</div><div><br></div><div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>Var:some_fun(Arg1, Arg2).</div></blockquote></div><div><div><div><div><br></div><div>The reasoning is that we had to maintain backwards compatibility since such calls were used by many projects. This behaviour has many downsides though, many of them debated in this mailing list, for example the performance hit of such calls as well as the fact this behaviour is confusing, specially when you accidentally trigger it for the first time.</div><div><br></div><div>Furthermore, erlang:apply/3 also allows tuple calls, not giving us any alternative to disallow such behaviour, even if it explicitly.</div><div><br></div><div>For those reasons, I would like to propose a new function and a compiler option that disables the tuple calls.</div><div><br></div></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><div><div>erlang:apply_no_tuple(Mod, Fun, Args).</div><div><br></div></div></div></div></blockquote><div><div><div><div>The function above works as apply, except it will raise badarg unless Mod is an atom. The idea is that the optimizations we had in mind for the regular dispatch could now be applied to this new function.</div><div><br></div><div>We could also have a compiler option, no_tuple_calls, that will compile all underlying Var:some_fun(Arg1, Arg2) into erlang:apply_no_tuple/3 instead of erlang:apply/3 for the current module. This is a great opportunity because build tools like rebar3, mix and <a href="http://erlang.mk" target="_blank">erlang.mk</a> could ship with such option as a default, slowly phasing out the tuple behaviour. In the long term, we could even make the tuple call behaviour opt-in (rather than opt-out).</div><div><br></div><div>PS: erlang:apply_no_tuple/3 and no_tuple_calls are horrible names but I believe we can find good names along the way if there is interest. Another alternative I had in mind was erlang:apply_strict/3 and only_strict_calls for the compiler option.</div></div></div></div><div><div><div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Lead Developer</span></div></span></div></span></div></div></div>
</div></div>