Module attributes with capital letter or reserved words

Hello,

I try to create modules attributes with reserved names or a capital letter but I have syntax errors. But I could not find some documentation about it. Could someone explain me why the parser (or the compiler ?) chokes here ?

Thank you

iex(1)> defmodule X do
...(1)> @when "ok"
...(1)> def add, do: @when
...(1)> end
** (SyntaxError) iex:2: syntax error before: 'when'

iex(1)> defmodule X do
...(1)> @Chen "ok"
...(1)> def add, do: @Chen
...(1)> end
** (SyntaxError) iex:2: syntax error before: "ok"

Is there a reason for the modules to not have names? defmodule has an arity of 2.

1 Like

According to the docs:

A custom attribute is any valid identifier prefixed with an @

when and Chen are no valid identifiers.

1 Like

Edited, thanks ! (But the errors are still the same since the body is evaluated before the call to defmodule)

NobbZ, so this means a name that could be a variable name, if I understand correctly.

Yes, exactly that.

Ok thank you !