[erlang-questions] basic import for code reuse

Robin robi123@REDACTED
Thu Dec 6 04:41:55 CET 2007


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











More information about the erlang-questions mailing list