Except it only uses those at compile time, and they are inline then, like here:
This is where you use Plug.Builder
, it defines a few function, sets a few compile-time variables (behaviour
and plug_builder_opts
), and at the end it does register an attribute to aggregrate an attribute. However, a module attribute at compile time is the same as just normal bindings in a normal function at runtime (it is runtime at compile-time), they are not accessible before defined and they can be rebound just like function bindings.
Even still, this relates to Purity, not Functionality, it is not entirely ‘pure’ as I think Module.register_attribute/3
sets something in an ETS table, but it is still Functional.
It is stateful in the same vein as bindings in a function are stateful, like this:
def something(a, b) do
c = a + b
blah(c)
end
This function is stateful in that there is intermediary state before the c = a + b
expression, a new state where c
is bound, you cannot use the c
binding before it is bound (state!), and the state is passed into the blah/1
call, but this is still Pure and Functional both.