nim-by-example
nim-by-example copied to clipboard
Formatting object types: No difference, as expected, in the last section
In the last section of the String Formatting chapter there's this example:
# note the difference here
echo &"hello {apple}" # hello (name: "apple", color: "red")
echo &"hello {$apple}" # hello Fruit("apple", "red")
The explanation in the text is as follows:
Note that the first line in the last section formats object types (and other types) using an in-built representation and you need to use the $ operator—as in the second line of the last section—if you want to coerce it to a format of your choosing.
When I run the code I get the same output for both lines:
hello Fruit(apple, red)
hello Fruit(apple, red)
For what it's worth, I'm using Nim 2.0.4.
Unfortunately I've not kept up with Nim. If you'd be willing to make a PR to correct this, I would gladly merge it.
In the meantime I've added a warning message to the top of each page to avoid misleading people: