Search code examples
juliaread-eval-print-loop

How to list all of Julia's internal variables?


Julia has a number of internal variables such as WORD_SIZE (indicates whether target system is 32- or 64-bit) and CPU_CORES (number of cpu cores presently available).

In the Julia REPL, is there some way to list all of these internal variables?

AFAIK, whos and names(Main) does not show them...

EDIT: From this previous question on listing exported function names, I see that names(Base) does show these internal variables, along with every other exported item in the Base module.


Solution

  • as @DNF pointed in the comment above, whos(Base.Sys) won't print all the internal(constant) variables in Base. but we can search those variables directly from whos(Base) via:

    julia> whos(Base, r"^\s*[A-Z_]+$")
                              ARGS      0 bytes  0-element Array{UTF8String,1}
                              BLAS    214 KB     Module
                         CPU_CORES      8 bytes  Int64
                            C_NULL      8 bytes  Ptr{Void}
                        ENDIAN_BOM      4 bytes  UInt32
                               ENV      0 bytes  Base.EnvHash with 29 entries
                              FFTW    149 KB     Module
                              HTML    168 bytes  DataType
                                 I      8 bytes  UniformScaling{Int64}
                                IO     92 bytes  DataType
                        JULIA_HOME     66 bytes  ASCIIString
                            LAPACK    933 KB     Module
                         LOAD_PATH    190 bytes  2-element Array{ByteString,1}
                              MIME    148 bytes  DataType
                           OS_NAME      0 bytes  Symbol
                            STDERR    217 bytes  Base.TTY
                             STDIN     64 KB     Base.TTY
                            STDOUT    217 bytes  Base.TTY
                           VERSION     40 bytes  VersionNumber
                         WORD_SIZE      8 bytes  Int64
    

    this lies in the fact that Julia's constants are UPPERCASE. you may find that some Modules are also in the list, but it's easy to identify. indeed, one can use a more complex regex to expel them.

    note that, those variables which are not exported into Base will not shown out. e.g.

    whos(Base.Libdl)