Zulip Chat Archive

Stream: lean4

Topic: Get full name of declaration


Tomas Skrivan (Mar 04 2024 at 22:43):

How do I get the full name of a declaration in macro/elaborator?

import Lean
open Lean Parser

namespace Foo
  def foo := 1
end Foo
open Foo

elab "#print_full_name" n:ident : command => do
  IO.println s!"short name: {n}"
  IO.println s!"full name: {n}" -- how do I get `Foo.foo ?

#print_full_name foo

I want the above to output

short name: foo
full name: Foo.foo

Damiano Testa (Mar 04 2024 at 22:49):

If there is only one possiblity, this works:

elab "#print_full_name" d:declId : command => do
  let nd  Lean.resolveGlobalConstNoOverload d.raw[0]
  IO.println nd

#print_full_name foo

Damiano Testa (Mar 04 2024 at 22:49):

Otherwise, removing the NoOverload will give you a list of possibilities.

Tomas Skrivan (Mar 04 2024 at 22:50):

Thanks, that is exactly the function I was looking for!

Kyle Miller (Mar 05 2024 at 01:53):

Why a declId @Damiano Testa ? That includes universe information, which you're dropping. You can do this too:

elab "#print_full_name" d:ident : command => do
  let nd  Lean.resolveGlobalConstNoOverload d
  IO.println nd

Tomas Skrivan (Mar 05 2024 at 02:02):

Because I had declId in my original question

Tomas Skrivan (Mar 05 2024 at 02:04):

But then realised that it should be just ident and simplified the mwe


Last updated: May 02 2025 at 03:31 UTC