__MODULE__ but for a function

__MODULE__ returns the name of the current module. Is there a way to return the name of the current function in a similar fashion?

__ENV__ seems to contain the info you’re looking for although I wonder why you need it/how do you plan to use it?

defmodule Example do
  def functie(input) do
    # IO.puts "Env is #{inspect __ENV__}"
    IO.puts "Current function is #{inspect __ENV__.function}"
    IO.puts input
  end
end

Example.functie "Hello World!"
# => Current function is {:functie, 1}
# => Hello World!
# => :ok
3 Likes