https://github.com/rizo/ppx_format
Simple syntax for string formatters.
https://github.com/rizo/ppx_format
Last synced: 3 months ago
JSON representation
Simple syntax for string formatters.
- Host: GitHub
- URL: https://github.com/rizo/ppx_format
- Owner: rizo
- License: mit
- Created: 2016-08-10T09:30:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-13T13:06:49.000Z (about 8 years ago)
- Last Synced: 2025-03-19T22:08:15.125Z (3 months ago)
- Language: OCaml
- Size: 5.86 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ppx_format
Simple syntax for string formatters. This extension features a syntax for string formatting inspired by Python. While processing the source code, each occurence of `"..." % (a, b, c)` is converted into `Printf.sprintf "..." a b c`.
**Examples**:
```ocaml
(* Format with one argument. *)
let () =
let name = Unix.getenv "USER" in
print_endline ("Hello, %s!" % name)(* Format with multiple arguments. *)
let () =
let name = Unix.getenv "USER" in
let time = Unix.time () in
let cdir = Unix.getenv "PWD" in
print_endline ("Hello %s! Current UNIX time is %f. Your current directory is %s" % (name, time, cdir))(* Partially applied format. *)
let () =
let hello = (%) "Hello, %s!" in
print_endline (hello "world")
```