Where are the attributes definitions defined in the file?

Why can the attribute ‘-compile().’ be defined anywhere in the module but not the attribute ‘-export().’

I don’t want to use -compile(export_all). in the following code. Export all functions because an error occurs when WINDOWS macros do not take effect

-module(some_mod).
-export([handle_c2s/2]).

handle_c2s(Arg,A) ->
   xxx_mod:a_xxx(Arg,A);

handle_c2s(Arg,B) ->
   xxx_mod:b_xxx(Arg,B);
...
handle_c2s(Arg,N) ->
   xxx_mod:n_xxx(Arg,N).

% TEST
-ifned(WINDOWS).
-export([test_a/2,test_b/2,... test_n/2]).

test(Arg,A) ->
   xxx_mod:a_test(Arg,A);

test(Arg,B) ->
   xxx_mod:b_test(Arg,B);
...
test(A,N) ->
   xxx_mod:n_test(A,N).

-endif.
1 Like

We tried to change that: Attributes mixed with functions · Issue #5689 · erlang/otp · GitHub

And, for a few seconds, we almost made it: make Erlang more tooling-friendly: allow custom attributes everywhere by ilya-klyuchnikov · Pull Request #5712 · erlang/otp · GitHub

:person_shrugging:

1 Like

Looking forward to OTP 26.0

1 Like

That’s good, but… remember that the merge was reverted. The change won’t happen anytime soon. Right, @bjorng?

Erlang parser itself doesn’t care about the relative position of the attributes, so you can use parse transform to move attributes from the middle of the module to the beginning. It’s a hack but it works (currently).

2 Likes