I currently delete all my user-defined variables like this.
varinfo()
variable1, variable2, variable3 = fill(nothing, 3)
Is there a way to make varinfo() output an array of only user-defined variable names instead of a markdown table with extra things like Base, Core, Main, and InteractiveUtils?
I don’t think so. The thing is that Base
, Core
, etc. are actually “variables” of Main
, i.e. Main.Base
and Main.Core
etc. In contrast, try this: module ABC end; varinfo(ABC)
.
What you can do is use the regex option of varinfo
to filter out Base
, Core
, etc.
1 Like
how to use the regex option?
Does this do the job for you?
julia> getvars() = [string(v) for v in sort!(names(Main)) if isdefined(Main, v) && !(v in (:Base, :Main, :Core, :InteractiveUtils, :ans))]
getvars (generic function with 1 method)
julia> getvars()
1-element Array{String,1}:
"getvars"
julia> x =5
5
julia> getvars()
2-element Array{String,1}:
"getvars"
"x"
julia> y = 10
10
julia> getvars()
3-element Array{String,1}:
"getvars"
"x"
"y"
5 Likes
This convenient function should a built-in function for Julia.
1 Like