lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

feat: add namespace utility function

Open fgdorais opened this issue 2 years ago • 8 comments

It was pointed out in std4#184 that this function is frequently reimplemented and that it may find a better home here.

fgdorais avatar Jul 21 '23 04:07 fgdorais

Functions I found implementing this function or a variant:

  • Lean.Elab.mkDeclName
  • Lean.Elab.Command.elabSyntax doesn't use the function, but should (see #2239). That PR introduces 4 reimplementations of the function
  • Lean.Elab.Term.elabWithDeclName should also be using the function (basically every use of (← getCurrNamespace) ++ id is suspect)

digama0 avatar Jul 21 '23 19:07 digama0

I'm wondering if removing the _root_ prefix from the rhs is a bit excessive. Maybe the user should decide whether to remove it afterwards.

fgdorais avatar Jul 21 '23 19:07 fgdorais

I think the function should be specced to always remove the _root_ prefix and return a fully qualified name. The use code can put _root_ on the front if needed. It shouldn't add the _root_ always because _root_ prefixed names aren't valid fully qualified names, they are a directive to whatever is processing the name to (suppress additional namespaces and) remove the _root_ before using the name, so you would only want to use that when putting the name back into syntax or similar to be re-processed.

digama0 avatar Jul 21 '23 19:07 digama0

Should it then also remove _root_ from the namespace prefix, or just assume that it is a proper namespace?

fgdorais avatar Jul 21 '23 20:07 fgdorais

Namespaces can't have _root_.

digama0 avatar Jul 21 '23 20:07 digama0

So it is fine as is, with a small edit to the docs?

fgdorais avatar Jul 21 '23 20:07 fgdorais

Fixed!

fgdorais avatar Jul 21 '23 21:07 fgdorais

std4#184 has evolved into std4#200, which doesn't currently use this function. I'm not unilaterally closing this since this PR could be useful for other purposes.

fgdorais avatar Jul 30 '23 16:07 fgdorais