<div dir="ltr"><div class="gmail_default" style="font-family:garamond,serif">You can use the function MODULE:module_info/1 something like </div><div class="gmail_default" style=""><span style="font-family:garamond,serif">is_defined(MyFunc, Arity, MODULE)-></span></div><div class="gmail_default" style=""><span style="font-family:garamond,serif">   Functions = MODULE:module_info(</span><font color="#1a1a1a" face="mono, Courier, monospace"><span style="font-size:16px;background-color:rgb(243,243,243)">functions</span></font><font face="garamond, serif">),</font></div><div class="gmail_default" style="">   lists:member({MyFunc,Arity}, Functions).</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Where MyFunc is an atom of course</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">You could also expand that to a call_function_if_defined_with_default/N but i will leave that to you</div><div class="gmail_default" style=""><br></div><div class="gmail_default" style="">Zach</div><div class="gmail_default" style=""><br></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><span style="font-family:garamond,serif">Zach Kessin - CEO Finch Software<br><font color="#000000">I boost sales with retail chatbots for fashion and cosmetics</font><br>+972 54 234 3956 / +44 203 734 9790 / +1 617 778 7213</span></div><div><font face="garamond, serif"><a href="https://calendly.com/zkessin/chatbot" target="_blank">Book a meeting with me</a></font></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Sat, Mar 3, 2018 at 9:42 PM, Metin Akat <span dir="ltr"><<a href="mailto:akat.metin@gmail.com" target="_blank">akat.metin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm looking into this code: <a href="https://github.com/erlang/otp/blob/master/lib/stdlib/src/gen_server.erl#L631" target="_blank">https://github.com/<wbr>erlang/otp/blob/master/lib/<wbr>stdlib/src/gen_server.erl#L631</a><br><div><br></div><div>Seems like this try/catch clause is implemented with the idea that most of the time it will succeed, as the callback module will have implemented the corresponding callback function, so we will not have to go into the exception clause where it needs to call erlang:function_exported/2 one more time (presumably as an additional safeguard) which is more expensive than an optimistic try clause.</div><div><br></div><div>I am writing something very similar, where such a check (is a function exported) will be performed by thousands/millions of processes on every message, but in my case... it's quite probable that most of the time this WILL raise the exception. In my case the function will be purely optional - if defined, it will return a value. If not, a default value will be used. </div><div><br></div><div>So my question is, how bad is this? I will test, but I'm still interested if someone has any ideas (maybe do something completely different).</div><div><br></div><div>Other possibilities are:</div><div><br></div><div>- Actually make the callback compulsory. I don't want to do that, as the problem I'm solving with this project is "See, you don't have to implement this boilerplate every time any more"</div><div><br></div><div>-  Put the option in application env where the user can configure it on startup. </div><div><br></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>