nim-by-example icon indicating copy to clipboard operation
nim-by-example copied to clipboard

Formatting object types: No difference, as expected, in the last section

Open emmanuelrosa opened this issue 1 year ago • 1 comments

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.

emmanuelrosa avatar Jun 24 '24 14:06 emmanuelrosa

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:

2024-07-06_19-17

flaviut avatar Jul 06 '24 23:07 flaviut