[erlang-questions] packages woe

Ulf Wiger ulf@REDACTED
Sat Mar 10 16:26:47 CET 2007


I'm having some trouble with packages (yes, I know, I know...)

I had a generated module that looked like this (pretty-printed):

-module(m).
-import('.lists', [reverse/1]).
-export([f/1]).

f(L) -> reverse(L).
---------------

Compiling it:

28> c(m).
./m.erl:3: bad module name '.lists'
./m.erl:6: function reverse/1 undefined

If I remove the single quotes in the import statement, it works, but it
works also in this case, which I think is strange:

-module(a.b.m).
-import(lists,[reverse/1]).
-export([f/1]).
f(L) -> reverse(L).

Looking at erl_lint, it converts the module name in import() to a string,
then calls packages:is_valid/1.

So...

31> packages:is_valid(".lists").
false
32> packages:is_valid('.lists').
true
33> packages:is_valid('a.b.m').
true
34> packages:is_valid("a.b.m").
true

(So '.lists' was ok, according to packages, but since erl_lint converted
it to a string first, it suddenly wasn't...)

It seems as if module names with a leading "." are handled inconsistently.
The functions split/1 and concat/1 add to the confusion:

37> packages:split(.lists).
["lists"]
38> packages:split('.lists').
[[],"lists"]
39> packages:concat(packages:split('.lists')).
"lists"

Apparently, packages:concat/1 is not a proper inverse to packages:split/1.

BR,
Ulf W




More information about the erlang-questions mailing list