[erlang-bugs] Parameterized modules and extends
Fyodor Ustinov
ufm@REDACTED
Thu Mar 15 20:22:10 CET 2012
Hi!
I understand this may be feature, not a bug.
I understand I'm say about absolutely undocumented things.
1.
-- file tt.erl --
-module(tt).
-export([tt/0, ee/0]).
tt() ->
io:format("tt:tt/0~n"),
ee()
.
ee() ->
io:format("tt:ee/0~n")
.
--file ttt.erl --
-module(ttt).
-extends(tt).
-export([tt/0, ttt/0]).
ttt() ->
io:format("ttt:ttt/0~n")
.
tt() ->
io:format("ttt:tt/0~n"),
ee()
.
--------------------
1> c(tt).
{ok,tt}
2> c(ttt).
ttt.erl:12: function ee/0 undefined
error
replace ee() to ttt:ee() fix this. But IMHO -extends should include -import.
2.
-- file tt.erl --
-module(tt,[M]).
-export([tt/0, ee/0]).
tt() ->
io:format("tt:tt/0 ~p ~p~n",[M, THIS]),
ee()
.
ee() ->
io:format("tt:ee/0 ~p ~p~n", [M, THIS])
.
-- file ttt.erl --
-module(ttt,[M]).
-extends(tt).
-export([tt/0, ttt/0]).
ttt() ->
io:format("ttt:ttt/0 ~p ~p~n",[M, THIS])
.
tt() ->
io:format("ttt:tt/0 ~p ~p~n", [M, THIS]),
ttt:ee()
.
----------
Erlang R15B (erts-5.9) [source] [64-bit] [async-threads:0]
[kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> c(tt).
{ok,tt}
2> c(ttt).
{ok,ttt}
3> {ttt, test}:ttt().
ttt:ttt/0 test {ttt,test}
ok
4> {tt, test}:tt().
tt:tt/0 test {tt,test}
tt:ee/0 test {tt,test}
ok
5> {ttt, test}:tt().
ttt:tt/0 test {ttt,test}
** exception error: undefined function tt:ee/0
6>
Oops. Hm. Ok. First attempt. Replace tt:ee() in ttt.erl to {ttt, M}:ee().
Eshell V5.9 (abort with ^G)
1> c(ttt).
ttt.erl:12: Warning: invalid module and/or function name; this call will
always fail
{ok,ttt}
2> {ttt, test}:tt().
ttt:tt/0 test {ttt,test}
tt:ee/0 test {ttt,test}
ok
3>
More better. But strange warning... Ok. Second attempt. Replace {ttt,
M}:ee() to THIS:ee().
Eshell V5.9 (abort with ^G)
1> c(ttt).
{ok,ttt}
2> {ttt, test}:tt().
ttt:tt/0 test {ttt,test}
tt:ee/0 test {ttt,test}
ok
3>
Nice. No strange warnings. But why do not work simple ttt:ee() ? BTW,
-import(tt, [ee/0]). and call simple ee() say the same:
Eshell V5.9 (abort with ^G)
1> c(ttt).
{ok,ttt}
2> {ttt, test}:tt().
ttt:tt/0 test {ttt,test}
** exception error: undefined function tt:ee/0
3>
WBR,
Fyodor.
P.S. IMHO 'extends' and 'Parameterized modules' it's a great feature.
Why this not documented yet?
More information about the erlang-bugs
mailing list