ANS Forth forbids modification of strings returned by the S" word (a.k.a. s-quote). (See also this discussion, ctrl-f for shall not alter.) This means that the Terminate-String word is non-compliant. More specifically, its intended use, in combination with S", is non-compliant.
I think the standard-compliant solution is to use the S\" word instead, where the \z sequence generates a null character, like '\0' in C, suitable for termination.
See also this StackOverflow thread, although he uses \0 rather than \z, which doesn't seem right.
From what I can see, ANS Forth offers no similar words for producing mutable strings. Perhaps a copy-based approach could also be made to work.
ANS Forth forbids modification of strings returned by the
S"word (a.k.a.s-quote). (See also this discussion, ctrl-f for shall not alter.) This means that theTerminate-Stringword is non-compliant. More specifically, its intended use, in combination withS", is non-compliant.I think the standard-compliant solution is to use the
S\"word instead, where the\zsequence generates a null character, like'\0'in C, suitable for termination.See also this StackOverflow thread, although he uses
\0rather than\z, which doesn't seem right.From what I can see, ANS Forth offers no similar words for producing mutable strings. Perhaps a copy-based approach could also be made to work.