Hello,
Here is a small example:
import strformat
let
str = "abc"
f = "{abc}"
echo fmt(f)
This fails with:
stack trace: (most recent call last)
lib/pure/strformat.nim(281) &
nim_src_rJX8ZE.nim(8, 10) Error: string formatting (fmt(), &) only works with string literals
So it looks like that failure is planned. So this post is more of a feature request.. Would it be possible to allow string variables be passed to fmt? Right now it seems to accept only string literals.
The above example is trivial, but a real use of allowing string variables can be seen in examples like this recent post of mine.
There I need to print with an alignment like this (the example output snippet in that post is created by Python):
B(36) = -26315271553053477373/1919190
B(38) = 2929993913841559/6
B(40) = -261082718496449122051/13530
So I need calculated the max length of the numerator portion of all the rationals and set the mininumwidth field in the fmt specifier accordingly.
For now, I am hard-coding that minimum width and doing this:
echo fmt"B({i:2}) = {bn[i]:>50}"
But if fmt accepted a string variable, I could have constructed that "B({i:2}) = {bn[i]:>50}" string, set that to a variable and passed that to fmt.