Pre 0.18.0:
var myString = "Some String"
echo "'", myString, "'" # --> echos 'Some String'
Post 0.18.0:
var myString = "Some String"
echo "'", myString, "'" # --> echos 'Some String ', notice the space (null character)
Is this here to stay or a regression?
Specs:
Works for me too.
Just tested it on Void Linux x64, with Nim 0.18.1 (recompiled a few hours ago with choosenim).
Windows, version 0.18.0:
'Some String'
Thanks @miran,
It may have been introduced in one of the mid 0.18.0 versions, because I tried it again on a friends Windows 10 x64, Nim 0.18.1 x64 machine and the error is present.
@miran, could you perhaps try it with a newer version of Nim?
Thanks
Sorry, my mistake! I showed the wrong code, it should be:
var myString = "Some String"
echo "'", myString[0 .. ^0], "'"
Sorry guys! Is this a regression?
Thanks @Krux02,
I had the same code from pre-0.18.0 and it worked with ^0, then recompiled it with 0.18.1 and it added the terminator, that is why I was confused. Then it seems to be a change?
Sorry again for the mistake guys.
I had the same code from pre-0.18.0 and it worked with ^0,
This reminds me of this issue.
The previous behaviour, where null terminator is ignored, is just wrong. You should change your program and use ^1 for the last character.
Btw, since it seems that at least two of you use(d) ^0, can I ask the rationale behind it? If you want something until the third-from-last character you use ..^3, second-from-last character ..^2, but if you want until the last character, you suddenly skip one number and use ..^0?
@miran certainly, the rationale is Python:
myString = "Some String"
print(myString[0 :]) # echos "Some String"
print(myString[0 : -1]) # echos "Some Strin"
That issue you linked explains it, thanks. I will mark this as solved.
the rationale is Python
Python's ranges have upper limit excluded, while Nim has upper limit included.
To mimic Python's range, use ..<.