[erlang-questions] Improve $handle_undefined_function

Loïc Hoguin <>
Tue Jan 22 13:02:10 CET 2013


On 01/22/2013 12:57 PM, Vlad Dumitrescu wrote:
> Hi,
>
> On Tue, Jan 22, 2013 at 12:10 PM, Loïc Hoguin <
> <mailto:>> wrote:
>
>     On 01/22/2013 07:34 AM, Björn Gustavsson wrote:
>
>         Why not use the existing -export() attribute and write like
>
>         this:
>
>         -export([monitor/2,demonitor/__1]).
>
>         monitor(process, Pid) ->
>              do_something.
>
>         demonitor(Pid) ->
>              do_something_else().
>
>         So what would be the advantage of your version?
>
>
>     It still allows Evan Miller to write this:
>
>     -attr([first_name/1, last_name/1, ...]).
>
>     $handle_undefined_function(F, [Model]) ->
>          {_, Value} = lists:keyfind(F, 1, Model),
>          Value.
>
>
> I'm sorry, but I don't think you are answering Björn's question. For
> this particular case, why not write regular Erlang like
>
> first_name(Model) -> get(first_name, Model).
> last_name(Model) -> get(last_name, Model).
> get(F, [Model]) ->
>      {_, Value} = lists:keyfind(F, 1, Model),
>      Value.
> which is much clearer to understand. One argument might be that there is
> some duplication, but I think that it could be handled with much more
> elegance if we had abstract patterns implemented.
>
> Do you have a more relevant example where using
> $handle_undefined_function gives significant advantage?

That's a question about $handle_undefined_function in general, not about 
this specific implementation proposal. Björn is the one who wrote the 
current implementation that's now in master, I don't have to tell him 
what can be done with it, he knows. I do have to tell him how 
implementing it this way improves the usage, though. Which is the sole 
reason of this thread.

-- 
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu



More information about the erlang-questions mailing list