function_name(f::Function) -> Symbol

Get the name of a generic Function as a symbol, or :anonymous.


julia> function_name(f::Function)
           return === nothing ? :anonymous :


  1. Get the name of a named function:

    julia> foo(x) = x^2;
    julia> function_name(foo)

    In this example, the function_name function returns the symbol :foo, which is the name of the foo function.

  2. Get the name of an anonymous function:

    julia> f = x -> x^2;
    julia> function_name(f)

    When an anonymous function is passed to function_name, it returns the symbol :anonymous.

  3. Handle a function without a name:
    julia> function_name(sin)

    The sin function is a built-in function without a name, so function_name returns :anonymous.

Common mistake example:

julia> function_name(123)
ERROR: MethodError: no method matching function_name(::Int64)

In this example, function_name is mistakenly called with an Int64 argument instead of a function. Ensure that the argument provided to function_name is a valid function to avoid such errors.

See Also

assert, backtrace, code_llvm, code_lowered, code_native, code_typed, code_warntype, :@which, compilecache, current_module, eval, finalize, finalizer, fullname, function_module, function_name, include_dependency, InterruptException, invoke, isconst, isdefined, isgeneric, methodswith, method_exists, module_name, module_parent, require, subtypes, unsafe_load, workspace, __precompile__,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: