How to find where constants are defined

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.

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

1 Like

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 from base/irrationals.jl.)


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

1 Like

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?

(Julia does store the module of the binding, which is why @which var can give the module; fun fact, this was added back in 2015.)

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

Yup, that’s correct.