isdefined
isdefined([object,] index | symbol)
Tests whether an assignable location is defined. The arguments can be an array and index, a composite object and field name (as a symbol), or a module and a symbol. With a single symbol argument, tests whether a global variable with that name is defined in current_module()
.
Examples
julia> x = 5
5
julia> isdefined(:x)
true
julia> isdefined(Main, :x)
true
julia> isdefined(:y)
false
julia> isdefined(Main, :y)
false
In the above examples:
isdefined(:x)
checks if the global variablex
is defined in the current module.isdefined(Main, :x)
checks if the global variablex
is defined in theMain
module.isdefined(:y)
checks if the global variabley
is defined in the current module.isdefined(Main, :y)
checks if the global variabley
is defined in theMain
module.
Note that isdefined
returns true
if the variable or field is defined, and false
otherwise.
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.