Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of current variables in Julia Lang

Tags:

julia

I am new to Julia Lang. I am coming from the background of Matlab.

In Matlab, when pressing whos command I will get all variables in the current scope; and also, I can store them in another variable like x=whos; Is there such commands exists in Julia? Example code in Matlab:

>> a=3; >> b=4; >> whos Variables in the current scope:  Attr Name        Size                     Bytes  Class ==== ====        ====                     =====  =====      a            1x1                          8  double     b            1x1                          8  double     prefix       1x16                        16  char  Total is 18 elements using 32 bytes. 
like image 563
vinu k n Avatar asked Jan 23 '14 07:01

vinu k n


People also ask

What are variables in Julia?

Variables A variable, in Julia, is a name associated (or bound) to a value. It's useful when you want to store a value (that you obtained after some math, for example) for later use.

What is the use of the load_path variable in Julia?

Unlike the shell PATH variable, empty entries in JULIA_LOAD_PATH are expanded to the default value of LOAD_PATH, ["@", "@v#.#", "@stdlib"] when populating LOAD_PATH. This allows easy appending, prepending, etc. of the load path value in shell scripts regardless of whether JULIA_LOAD_PATH is already set or not.

How does Julia determine the path of the Julia executable?

The absolute path of the directory containing the Julia executable, which sets the global variable Sys.BINDIR. If $JULIA_BINDIR is not set, then Julia determines the value Sys.BINDIR at run-time. by default. The global variable Base.DATAROOTDIR determines a relative path from Sys.BINDIR to the data directory associated with Julia. Then the path

How do I find the current value of the same environment variable?

The current value of the same environment variable can be determined by evaluating ENV ["JULIA_EDITOR"]. The environment variables that Julia uses generally start with JULIA.


2 Answers

An Update:

whos()  

... is not working either in iJulia or at the command prompt in Julia-1.0.0.

It is working in Julia-0.6.4, though.

On the other hand,

varinfo() 

....prints information about the exported global variables in a module. For Example,

julia-1.0> varinfo() name                    size summary                         –––––––––––––––– ––––––––––– ––––––––––––––––––––––––––––––– Base                         Module                          Core                         Module                          InteractiveUtils 154.271 KiB Module                          Main                         Module                          PyPlot           781.872 KiB Module                          ans               50.323 KiB Plots.Plot{Plots.PyPlotBackend} myrepl               0 bytes typeof(myrepl)                  x                   88 bytes 1×6 Array{Int64,2}              y                    0 bytes typeof(y)                       

Hope, this is found useful.

like image 178
Long short Avatar answered Sep 22 '22 00:09

Long short


You can use Julia's whos functions just like that Matlab command.

julia> whos() Base                          Module Core                          Module Main                          Module ans                           Nothing  julia> x = 5 5  julia> whos() Base                          Module Core                          Module Main                          Module ans                           Int64 x                             Int64 

Any modules (packages/libraries) you import into your local scope (using using) will also show up in the list (as Modules, like Base, Core, and Main above).

Additionally, you can ask about names exported by Modules. Base is the module containing the standard library.

julia> whos(Base) !                             Function !=                            Function !==                           Function $                             Function %                             Function &                             Function *                             Function +                             Function .... (lots and lots more) 

Considering that that result scrolls way off my screen, you can understand why you'd want to filter the results. For that you can use Regexes. (For more info on Julia's regexes, see this manual section)

julia> whos(r"M") Main                          Module  julia> whos(Base, r"Match"i) DimensionMismatch             DataType RegexMatch                    DataType each_match                    Function eachmatch                     Function ismatch                       Function match                         Function matchall                      Function 

I wasn't aware of the whos function before you asked, so thanks for helping me learn something new too. :)

Julia issue #3393 on github is about adding memory sizes to the whos output. It also references making whos return a value rather than just printing the information out.

like image 34
astrieanna Avatar answered Sep 25 '22 00:09

astrieanna