6 ms·
Can you link to Nim's userland implementation of printf? Here's zig: https://github.com/ziglang/zig/blob/822d4fa216ea8f598e4a9d53161800494f449a94/std/fmt/index.
by AndyKelley 8y ago
Can you link to Nim's userland implementation of printf? Here's zig: https://github.com/ziglang/zig/blob/822d4fa216ea8f598e4a9d53161800494f449a94/std/fmt/index.zig#L15 https://github.com/ziglang/zig/blob/822d4fa216ea8f598e4a9d53...
- simen 8y agoI 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/master/stringinterpolation.nim 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 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.
- dom96 8y agoNim also has this in the stdlib now: https://nim-lang.org/docs/strformat.html https://nim-lang.org/docs/strformat.html
- k__ 8y agoWhat I meant was "macros written in Nim for Nim" which they called macros and not "we don't have macros, because we have them, but we don't call them macros, so we can say we are simpler because we don't have macros!" XD