Hi. I'm tried to do something like a:
var s = "str123"
s.add(s)
echo s
I'm expected 'str123str123', but got 'str123str123s'. Why did appeared the last symbol 's'? What difference beetween concateration (&) and adding strings?Probably because you are manipulating the string itself while coyping from it. If this should be allowed, then the code should make a copy of the original size before manipulating the target in add. Sounds like a bug that could easily be fixed.
Edit: I don't see this behaviour in the current devel branch, so it might have been fixed or be system dependent.
That unexplained trailing 's' character does NOT appear for me on v0.17.2, including in a local installation of Nim Playground.
I do see it on play.nim-lang.org (which is used by this forum's "Run" button). So it's probably a bug in whatever version of Nim is used there.
System add...
proc add*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
It's a proc, Jim, but not as we know it...
It's MAGIC! :P
From what I understand, this is done so that different code generators (C, JS, VM, etc) can do it differently.