https://github.com/leoslf/printf.lean
A lightweight Lean 4 implementation of the C‑style printf format and output functionality
https://github.com/leoslf/printf.lean
lean4 printf
Last synced: 3 months ago
JSON representation
A lightweight Lean 4 implementation of the C‑style printf format and output functionality
- Host: GitHub
- URL: https://github.com/leoslf/printf.lean
- Owner: leoslf
- License: mit
- Created: 2025-07-09T23:52:49.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2025-08-15T07:33:28.000Z (5 months ago)
- Last Synced: 2025-08-25T12:59:28.228Z (5 months ago)
- Topics: lean4, printf
- Language: Lean
- Homepage: https://leoslf.github.io/printf.lean/
- Size: 47.9 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 📣 Lean 4 `printf` Implementation
A lightweight Lean 4 implementation of the C‑style `printf` format and output functionality — inspired by `printf`, `sprintf`, and `snprintf`.
This lets you format strings directly in Lean, without resorting to FFI.
## Features
- C-style format specifiers: `%d`, `%f`, `%s`, `%x`, etc.
- Variadic formatting interface in Lean 4
- Pure Lean (no libc or FFI dependencies)
- Extensible format specifier support
## Usage Examples
```lean
import Printf
open Printf
#eval printf "%s: %d + %d = %d\n" "Sum" 2 7 9
-- Output: Sum: 2 + 7 = 9
#eval printf "Pi ≈ %.3f" 3.1415926
-- Returns: "Pi ≈ 3.142"
```
# References
Haskell.org, 2025. https://hackage.haskell.org/package/base-4.21.0.0/docs/src/Text.Printf.html (accessed Aug. 15, 2025).