In working with the ExUnit code, there are at least two places where I 
think being able to introspect on module attributes would be useful.

One is here 
<https://github.com/elixir-lang/elixir/blob/master/lib/ex_unit/lib/ex_unit/case.ex#L227-L233>.
 
In this code it would be useful to know if a module attribute has been set 
already. This code checks to see if it has a value. However, if a user set 
the value to `nil`, this code wouldn't be able to tell.

Another situation it would be useful, is in this PR: 
https://github.com/elixir-lang/elixir/pull/9181. Specifically, this check 
<https://github.com/elixir-lang/elixir/blob/e24a18338ef908aba8bf83e315d6e3938dbefce7/lib/ex_unit/lib/ex_unit/case.ex#L427-L431>,
 
where it would also be useful to know if the attribute is registered with 
accumulate or not.

So, the proposal is an API something like this:

defmodule X do
  Module.register_attribute(__MODULE__, :foo, accumulate: true)
  @bar true
 
  Module.attribute_registered?(__MODULE__, :foo) #=> true
  Module.attribute_registered?(__MODULE__, :foo, accumulate: true) #=> true
  Module.attribute_registered?(__MODULE__, :foo, persist: true) #=> false

  Module.attribute_registered?(__MODULE__, :bar) #=> true
  Module.attribute_registered?(__MODULE__, :bar, accumulate: true) #=> false

  Module.attribute_registered?(__MODULE__, :baz) #=> false
end

The third argument would be a subset match of the options. 

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/39c87e02-8ed2-49ed-9754-d0e8f0bafd7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to