# Standard Module Main, Core, Base definition

**URL:** <https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [May 8, 2022, 2:07pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712 "2022-05-08T14:07:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [May 8, 2022, 2:07pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/1 "2022-05-08T14:07:13Z")

</div>

In Julia Manual, it says that “There are three important standard modules: Main, Core, and Base.”, But I just wonder where are these modules defined, can we find their file path? By the way, are there smart methods to find file path where certain function is defined within Julia?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 8, 2022, 2:09pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/2 "2022-05-08T14:09:51Z")

</div>

> [@Hawk](#):
>
> smart methods to find file path

try running this in REPL

```julia
@which sin(3.0)
# or
@edit sin(3.0)

```

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [May 8, 2022, 2:14pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/3 "2022-05-08T14:14:19Z")

</div>

Thanks, macro @which and @edit are clever ideas to find file path where their definitions locate. So is there the similar method to find definition for Module like Main and Core, because when I type @which for Core and Main, it shows:

```julia
@which Core
Main
@which Main
Main

```

But I still do not know where they locate 😭

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 8, 2022, 2:15pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/4 "2022-05-08T14:15:10Z")

</div>

their definition is not useful, because they essentially made up the Julia as you know:

> <https://github.com/JuliaLang/julia/blob/d4acead9130f97f0135bee604d94e1f67dabc70f/base/Base.jl#L3>

they are important in the sense that they exist (almost) universally whenever you use Julia.

Besides `Base`, `Main` is your top level in REPL, and `Core` is not defined from Julia (think of it has bootstrap).

Again, their exact definition is not important, because it’s basically what makes Julia usable for you

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [May 8, 2022, 2:17pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/5 "2022-05-08T14:17:44Z")

</div>

So how are you find their locations so quickly, any good ideas?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 8, 2022, 2:18pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/6 "2022-05-08T14:18:46Z")

</div>

it’s in `base/Base.jl`, the convention is `module X` top level locates in a file named `X.jl`… that’s all…

> <https://github.com/JuliaLang/Example.jl/blob/9f288cc4864dbfc2c82338caac0b1eb1fc7ff87f/src/Example.jl#L1>

---

<div class="post-metadata">

**Author:** ![Hawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawk/32/16763_2.png) [@Hawk](https://discourse.julialang.org/u/Hawk)\
**Post date:** [May 8, 2022, 2:27pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/7 "2022-05-08T14:27:48Z")

</div>

Thanks. I see, at present, digging into julia too much about all stuffs seems not a good idea for me…

---

<div class="post-metadata">

**Author:** ![yashi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yashi/32/19448_2.png) [@yashi](https://discourse.julialang.org/u/yashi)\
**Post date:** [May 9, 2022, 11:58am UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/8 "2022-05-09T11:58:27Z")

</div>

Yeah, I can feel that.

For a noob like me, a macro or a function to print where the given functions, variables, modules, or any objects would be a great help. I don’t care I actually understand it. I just want to read them for learning.

At first, I didn’t understand why `edit()` doesn’t work for `Core`, `Main`, or `Base`. But it works for `InteractiveUtils`.

Also, `edit()` can handle modules but `less()` doesn’t seems so.

```julia
julia> names(Main)
4-element Vector{Symbol}:
 :Base
 :Core
 :InteractiveUtils
 :Main

julia> edit(Base)
ERROR: object is not callable
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] functionloc(f::Any)
   @ Base ./methodshow.jl:182
 [3] edit(f::Any)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:229
 [4] edit(m::Module)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:236
 [5] top-level scope
   @ REPL[2]:1

julia> edit(Core)
ERROR: object is not callable
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] functionloc(f::Any)
   @ Base ./methodshow.jl:182
 [3] edit(f::Any)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:229
 [4] edit(m::Module)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:236
 [5] top-level scope
   @ REPL[3]:1

julia> edit(Main)
ERROR: object is not callable
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] functionloc(f::Any)
   @ Base ./methodshow.jl:182
 [3] edit(f::Any)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:229
 [4] edit(m::Module)
   @ InteractiveUtils ~/julia-1.7.2/share/julia/stdlib/v1.7/InteractiveUtils/src/editless.jl:236
 [5] top-level scope
   @ REPL[4]:1

julia> edit(InteractiveUtils)

julia>
```

---

<div class="post-metadata">

**Author:** ![yashi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yashi/32/19448_2.png) [@yashi](https://discourse.julialang.org/u/yashi)\
**Post date:** [May 9, 2022, 12:07pm UTC](https://discourse.julialang.org/t/standard-module-main-core-base-definition/80712/9 "2022-05-09T12:07:34Z")

</div>

You can actually read `edit()` to see how it finds various objects:

```julia
function edit(@nospecialize f)
    ms = methods(f).ms
    length(ms) == 1 && edit(functionloc(ms[1])...)
    length(ms) > 1 && return ms
    length(ms) == 0 && functionloc(f) # throws
    nothing
end
edit(m::Method) = edit(functionloc(m)...)
edit(@nospecialize(f), idx::Integer) = edit(methods(f).ms[idx])
edit(f, t) = (@nospecialize; edit(functionloc(f, t)...))
edit(file::Nothing, line::Integer) = error("could not find source file for function")
edit(m::Module) = edit(pathof(m))

```

And `Base.module_keys` to see how the Module are managed internally. Note that `Core`, `Main`, and `Base` are `[top-level]`.

```julia
julia> Base.module_keys
IdDict{Module, Base.PkgId} with 44 entries:
  DelimitedFiles => DelimitedFiles [8bb1440f-4735-579b-a4ab-409b98df4dab]
  SuiteSparse => SuiteSparse [4607b0f0-06f3-5cda-b6b1-a6196a1729e9]
  Downloads => Downloads [f43a241f-c20a-4ad4-852c-f6b1247861c6]
  LibCURL_jll => LibCURL_jll [deac9b47-8bc7-5906-a0fe-35ac56dc84c0]
  Base64 => Base64 [2a0f44e3-6c83-55bd-87e4-b1978d98bd5f]
  SHA => SHA [ea8e919c-243c-51af-8825-aaa63cd721ce]
  Artifacts => Artifacts [56f22d72-fd6d-98f1-02f0-08ddc0907c33]
  LazyArtifacts => LazyArtifacts [4af54fe1-eca0-43a8-85a7-787d91b784e3]
  CRC32c => CRC32c [8bf52ea8-c179-5cab-976a-9e18b702a9bc]
  Core => Core [top-level]
  Main => Main [top-level]
  SparseArrays => SparseArrays [2f01184e-e22b-5df5-ae63-d93ebab69eaf]
  Distributed => Distributed [8ba89e20-285c-5b6f-9357-94700520ee1b]
  Serialization => Serialization [9e88b42a-f829-5b0c-bbe9-9e923198166b]
  TOML => TOML [fa267f1f-6049-4f14-aa54-33bafae1ed76]
  Base => Base [top-level]
  Markdown => Markdown [d6f4376e-aef5-505a-96c1-9c027394607a]
  ArgTools => ArgTools [0dad84c5-d112-42e6-8d28-ef12dabb789f]
  nghttp2_jll => nghttp2_jll [8e850ede-7688-5339-a07c-302acd2aaf8d]
  InteractiveUtils => InteractiveUtils [b77e0a4c-d291-57a0-90e8-8db25a27a240]
  Sockets => Sockets [6462fe0b-24de-5631-8697-dd941f90decc]
  Profile => Profile [9abbd945-dff8-562f-b5e8-e1ebf5ef1b79]
  LibCURL => LibCURL [b27032c2-a3e7-50c8-80cd-2d36dbcbfd21]
  Libdl => Libdl [8f399da3-3557-5675-b5ff-fb832c97cbdb]
  Printf => Printf [de0858da-6303-5e67-8744-51eddeeeb8d7]
  Statistics => Statistics [10745b16-79ce-11e8-11f9-7d13ad32a3b2]
  SharedArrays => SharedArrays [1a1011a3-84de-559e-8e89-a11a2f7dc383]
  Random => Random [9a3f8284-a2c9-5f02-9a11-845980a1fd5c]
  MozillaCACerts_jll => MozillaCACerts_jll [14a3606d-f60d-562e-9121-12d972cd8159]
  p7zip_jll => p7zip_jll [3f19e933-33d8-53b3-aaab-bd5110c3b7a0]
  Tar => Tar [a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e]
  LinearAlgebra => LinearAlgebra [37e2e46d-f89d-539d-b4ee-838fcccc9c8e]
  FileWatching => FileWatching [7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee]
  Logging => Logging [56ddb016-857b-54e1-b83d-db4d58db5568]
  Pkg => Pkg [44cfe95a-1eb2-52ea-b672-e2afdf69b78f]
  Mmap => Mmap [a63ad114-7e13-5084-954f-fe012c677804]
  Unicode => Unicode [4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5]
  LibGit2 => LibGit2 [76f85450-5226-5b5a-8eaa-529ad045b433]
  Dates => Dates [ade2ca70-3891-5945-98fb-dc099432e06a]
  UUIDs => UUIDs [cf7118a7-6976-5b1a-9a39-7adc72f591a4]
  REPL => REPL [3fa0cd96-eef1-5676-8a61-b3b8758bbffb]
  NetworkOptions => NetworkOptions [ca575930-c2e3-43a9-ace4-1e988b2c1908]
  Test => Test [8dfed614-e22c-5e08-85e1-65c5234f0b40]
  Future => Future [9fa8497b-333b-5362-9e8d-4d0656e87820]

```
