-
Notifications
You must be signed in to change notification settings - Fork 710
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
[Clear and concise description of the issue]
Context
Lean's numeric literal syntax supports underscores as digit separators for readability:
def myNumber : Nat := 100_000_000 -- ✅ WorksHowever, String.toNat? (and String.toInt?) do not support this syntax:
#eval "100_000_000".toNat? -- Returns `none` ❌
#eval "100000000".toNat? -- Returns `some 100000000` ✅This inconsistency creates friction when parsing user input, command-line arguments, environment variables, or configuration files where users reasonably expect the same syntax they use in Lean code.
Steps to Reproduce
#eval "100_000_000".toNat? -- Returnsnone❌#eval "100_000_000".toInt? -- Returnsnone❌
Expected behavior: [Clear and concise description of what you expect to happen]
#eval "100_000_000".toNat? -- Returnssome 100000000` ✅#eval "100_000_000".toInt? -- Returnssome 100000000` ✅
Actual behavior: [Clear and concise description of what actually happens]
#eval "100_000_000".toNat? -- Returnsnone❌#eval "100_000_000".toInt? -- Returnsnone❌
Versions
[Output of #version or #eval Lean.versionString]
"4.27.0-nightly-2025-11-30"
[OS version, if not using live.lean-lang.org.]
Additional Information
[Additional information, configuration or data that might be necessary to reproduce the issue]
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Libraries that parse numeric arguments (like lean4-cli) inherit this limitation since they rely on String.toNat?.
I stumbled on this issue while drafting a PR for this issue:
leanprover/doc-gen4#335