Check if the objects or variables are defined in Julia – isdefined() and @isdefined() Methods
The isdefined()
is an inbuilt function in julia which is used to test whether the specified global variable or object field is defined or not. The passed parameters can be a module and a symbol or a composite object and field name (as a symbol) or index.
Syntax:
isdefined(m::Module, s::Symbol)
or
isdefined(object, s::Symbol)
or
isdefined(object, index::Int)
Parameters:
- m::Module: Specified module.
- s::Symbol: Specified symbol.
- object: Specified composite object.
- index::Int: Specified index.
Returns: It returns true for the defined specified global variable or object field else returns false.
Example:
println(isdefined(Base, : sum ))
println(isdefined(Base, :num))
println(isdefined(Base, :NonExistentMethod))
a = 2 / / 3 ;
println(isdefined(a, 1 ))
println(isdefined(a, 2 ))
println(isdefined(a, :num))
println(isdefined(a, :numerator))
|
Output:
true
true
false
true
true
true
false
@isdefined()
The @isdefined()
is an inbuilt function in julia which is used to tests whether the specified variable s is defined in the current scope or not.
Syntax:
@isdefined s
Parameters:
Returns: It returns true if the specified variable s is defined in the current scope else returns false.
Example:
function f()
println(@isdefined x)
x = 10
println(@isdefined x)
end
f (generic function with 1 method)
println(f())
|
Output:
Last Updated :
01 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...