[erlang-questions] basic import for code reuse

Robin robi123@REDACTED
Thu Dec 6 06:49:49 CET 2007


lw_template.erl:
-module(lw_template).
-compile(export_all).
member() -> template.

lw_special.erl:
-module(lw_special).
-compile(export_all).
-import(lw_template, [member/0]).
member() -> special.

The error output:
Eshell V5.5.5  (abort with ^G)
1> lw_special:member().
** exited: {undef,[{lw_special,member,[]},
                   {erl_eval,do_apply,5},
                   {shell,exprs,6},
                   {shell,eval_loop,3}]} **

Is there any technical reason that you cannot override an imported
function?

Thanks,

Robin


On Dec 5, 7:41 pm, Robin <robi...@REDACTED> wrote:
> This is a simple example using -import:
>
> -module(lw_template).
> -compile(export_all).
> member() -> template.
>
> -module(lw_special).
> -compile(export_all).
> -import(lw_template, [member/0]).
> member() -> special.
>
> When I import member/0 and then override it, the compiler gives the
> warning:
>
> lw_special.erl: defining imported function member/0
>
> When I call member/0, the runtime bombs with an error:
>
> Eshell V5.5.5  (abort with ^G)
> 1> ls_special:member().
> ** exited: {undef,[{ls_special,member,[]},
>                    {erl_eval,do_apply,5},
>                    {shell,exprs,6},
>                    {shell,eval_loop,3}]} **
>
> Import followed by override does not work above, so how else can you
> specialize an imported function at compile time?
>
> If the runtime bombs from overriding a function, then should the
> compiler produce an error rather than just a warning?
>
> thanks,
>
> Robin
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questi...@REDACTED://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list