[erlang-questions] Why we need a -module() attribute?

Loïc Hoguin essen@REDACTED
Tue Feb 23 22:20:04 CET 2016


On 02/23/2016 08:53 PM, Kenneth Lakin wrote:
> On 02/23/2016 10:12 AM, Judson Lester wrote:
>> I'd really like to be able to put that in src/myapp/part/subpart.erl -
>> maybe this is a misapprehension turned superstition, but I was under the
>> impression that I'd need to have a whole separate build step to copy the
>> latter into the former before handing it to erlc. Is that not the case?
>
> It doesn't seem to be the case. This works just fine for me with Erlang 18:
>
> $ ls
> $ mkdir -p dir/with/parents
> $ echo "-module (test).
>> -compile (export_all).
>>
>> run() -> ok." > dir/with/parents/test.erl
> $ erlc dir/with/parents/test.erl
> $ ls
> dir  test.beam

Interestingly, if -module was optional, this would open the way to tools 
being able to create the dir_with_parents_test.beam by concatenating the 
path segments. Erlang.mk has an option to do this with ErlyDTL templates 
already, it could be interesting to see this for Erlang source files.

-- 
Loïc Hoguin
http://ninenines.eu
Author of The Erlanger Playbook,
A book about software development using Erlang



More information about the erlang-questions mailing list