3 ms·
> because performance matters - concat(a,b) is just "{a}{b}" if and only if a compiler is sufficiently smart to reduce it to the minimum of operations needed I
by josefx 3y ago
> because performance matters - concat(a,b) is just "{a}{b}" if and only if a compiler is sufficiently smart to reduce it to the minimum of operations needed
If I remember correctly these kinds of format strings have to be resolved by the compiler since they refer to variables in the source by name, which is information most languages do not keep around at runtime and a security nightmare if done dynamically. Also performance sensitive language like C aren't exactly known for a fast strcat, it is usually left as an exercise to the user to avoid catastrophic runtime behavior caused by the eternal search for nul.
- matheusmoreira 3y agoI suppose format strings can be transformed into a series of concatenation function calls. Or a single n-arity call. (format "{a} {b} cde {f}") Could be a macro that returns: (concat a " " b " cde " f) The non-trivial part seems to be replacing the original format call site with the compiled version in the code. When I try to think it through, I conclude that everything should be a macro that outputs a compiled program. Just seems wrong in a dynamic language but it seems people do it all the time: https://news.ycombinator.com/item?id=39240528 https://news.ycombinator.com/item?id=39240528 Partially evaluated programs.