DataTypes
have a mutable
field, so you can define is_mutable
and is_immutable
using this, since doing this instead of directly accessing this field is more Julian.
Using Julia version 0.5.0 :
_ _ _ _(_)_ | By greedy hackers for greedy hackers. (_) | (_) (_) | Documentation: http://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _' | | | | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-w64-mingw32
julia> DataType.
Create type
and immutable
and instances for both of them:
julia> type Foo end julia> f = Foo() Foo() julia> immutable Bar end julia> b = Bar() Bar()
Check for variability:
julia> is_mutable(Foo), is_mutable(f) (true,true) julia> is_mutable(Bar), is_mutable(b) (false,false)
Check for immutability:
julia> is_immutable(Foo), is_immutable(f) (false,false) julia> is_immutable(Bar), is_immutable(b) (true,true)
For performance, also consider declaring these functions as @pure
:
Base.@pure is_mutable(x::DataType) = x.mutable
source share