Hacker News new | ask | show | jobs
by simen 2799 days ago
I don't think Nim has one in the standard library, but people have built variations on it. Here's a couple:

* https://github.com/bluenote10/nim-stringinterpolation/blob/m... This one does string interpolation and a printf-like syntax with compile time type checking. It does call out to C but only after it's already parsed and validated and transformed the format string.

* https://github.com/kaushalmodi/strfmt/blob/master/strfmt.nim This one implements a more complex string formatting syntax with lots of convenience functions. It's more complex but provides a lot more functionality than the previous one without relying on FFI.

I'm not a Nim programmer but I imagine those two demonstrate how Nim metaprogramming works even if neither exactly duplicates the behavior of printf.

1 comments

Nim also has this in the stdlib now: https://nim-lang.org/docs/strformat.html