# How to find where constants are defined

**URL:** https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936
**Category:** General Usage
**Tags:** constants
**Created:** [January 20, 2022, 1:12pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936 "2022-01-20T13:12:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [January 20, 2022, 1:12pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/1 "2022-01-20T13:12:22Z")

</div>

Is there a way to reveal the file where constants are defined? For example, we have `π = 3.1415926535897...`, but which file defines this constant? I am looking for something like `@less` for functions.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [January 20, 2022, 1:31pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/2 "2022-01-20T13:31:26Z")

</div>

Good question, you can get the module with `@which` but it does not give the file and exact line.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 20, 2022, 1:34pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/3 "2022-01-20T13:34:43Z")

</div>

To find the exact file and line, I think that currently the easiest way is to use an editor or `grep` tool to search for `const foo =`.

(The particular example of π is in `base/mathconstants.jl`, but it’s hard to `grep` for because it’s defined [via a macro](https://github.com/JuliaLang/julia/blob/88b1f9237a65aaee315824d408e9feb83151c2d2/base/mathconstants.jl#L13) from [base/irrationals.jl](https://github.com/JuliaLang/julia/blob/88b1f9237a65aaee315824d408e9feb83151c2d2/base/irrationals.jl#L164-L197).)

---

<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: [January 20, 2022, 2:05pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/4 "2022-01-20T14:05:21Z")

</div>

LSP must have a way to do it (LanguageServer.jl), I wonder if that part can be migrated to Julia so we have a `varloc` or `constloc` like existing `functionloc`

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 20, 2022, 2:59pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/5 "2022-01-20T14:59:58Z")

</div>

I don’t think the Julia parser actually stores this information, so maybe LanguageServer.jl is relying on re-parsing the Julia code with [CSTParser.jl](https://github.com/julia-vscode/CSTParser.jl)?

(Julia [does store](https://github.com/JuliaLang/julia/blob/f67371dcc27d1f93d6b9d79261de4b396bf72477/src/julia.h#L501-L511) the module of the binding, which is why `@which var` can give the module; fun fact, this was added [back in 2015](https://github.com/JuliaLang/julia/pull/7322).)

---

<div class="post-metadata">

### Author: ![wsshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wsshin/32/360_2.png) [@wsshin](https://discourse.julialang.org/u/wsshin)
#### Post date: [January 20, 2022, 4:40pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/6 "2022-01-20T16:40:49Z")

</div>

Thanks all! `@which` followed by `grep` is sufficient for now. I will try `LanguageServer.jl` if more sophisticated search is needed.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [January 20, 2022, 4:43pm UTC](https://discourse.julialang.org/t/how-to-find-where-constants-are-defined/74936/7 "2022-01-20T16:43:38Z")

</div>

> [@stevengj](#):
>
> I don’t think the Julia parser actually stores this information, so maybe LanguageServer.jl is relying on re-parsing the Julia code with [CSTParser.jl](https://github.com/julia-vscode/CSTParser.jl)?

Yup, that’s correct.
