While looking over the source code for a library I’m using, I noticed that there were several times that the same module attribute (
@params) was defined in the same module – the author was using this as a way to define default values for each function.
In a nutshell:
@params [:a, :b:, :c] def a() # do something with @params end @params [:d, :e] def b() # do something with @params end
My IDE flagged these as invalid, but are they? My understanding was that these are evaluated at compile time.
Although there’s no mention of the uniqueness of module attributes on https://elixir-lang.org/getting-started/module-attributes.html I know that in test modules, it’s common to have multiple instances of the
@tag attributes that decorates each function. Same for the
@impl tag used when implementing behaviours.
Can someone help clarify what’s going on there and if that is valid?