| Author |
Message |
|
| Guest |
Posted: Thu Dec 06, 2007 5:18 am |
|
|
|
Guest
|
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-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist |
|
|
| Back to top |
|
| Guest |
Posted: Thu Dec 06, 2007 6:02 am |
|
|
|
Guest
|
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...@gmail.com> 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...@erlang.orghttp://www.erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist |
|
|
| Back to top |
|
| Adam |
Posted: Thu Dec 06, 2007 1:18 pm |
|
|
|
User
Joined: 23 Aug 2006
Posts: 71
Location: London
|
Yes there is a technical reason, if you call the function member/0 in your module, how should the compiler know which module you intented to call? The imported one or the one declared in your module?
Overriding is not possible in Erlang at the moment. Although there was a presentation on the subject (and others) and the Erlang User Conference (EUC) this year: http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
One simple way to "solve" your problem though is to just not import the member/0 function in the module you want to override it in. This way both module will have the member/0 function anyway. Thus you have to tell the modules that are not to override it to import the template function instead.
Cheers,
Adam
On Dec 6, 2007 6:49 AM, Robin <robi123@gmail.com (robi123@gmail.com)> wrote:
Quote: 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 |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|