names

names(x::Module[, all=false[, imported=false]])

Get an array of the names exported by a Module, with optionally more Module globals according to the additional parameters.

Examples

  1. Get the names of exported functions in a module:

    julia> module MyModule
              export foo, bar, baz
              function foo()
                  println("This is foo")
              end
              function bar()
                  println("This is bar")
              end
              function baz()
                  println("This is baz")
              end
          end
    
    julia> names(MyModule)
    3-element Array{Symbol,1}:
    :bar
    :baz
    :foo

    This example returns an array of symbols representing the names of the functions exported by the module MyModule.

  2. Get all names in a module, including imported names:

    julia> using LinearAlgebra
    
    julia> names(Main, all=true)
    4-element Array{Symbol,1}:
    :LinearAlgebra
    :Main
    :MyModule
    :Sys

    Here, names is used to retrieve all names in the Main module, including imported modules like LinearAlgebra.

  3. Get only the imported names in a module:

    julia> using Statistics
    
    julia> names(Main, all=false, imported=true)
    1-element Array{Symbol,1}:
    :Statistics

    In this example, names is used to fetch only the imported module names in the Main module.

Common mistake example:

julia> module MyModule
           export foo, bar, baz
           function foo()
               println("This is foo")
           end
           function bar()
               println("This is bar")
           end
           function baz()
               println("This is baz")
           end
       end

julia> names(MyModule, all=true)
ERROR: MethodError: no method matching names(::Module, ::Bool)

In this example, the names function is mistakenly used with the all parameter on a module. The all parameter is applicable only when used with the Main module.

See Also

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
Details

Checking you are not a robot: