2 ms·
I've done a fair bit of forth and I've not seen c" used. The usual string printing operator is ." .
by llm_trw 2y ago
I've done a fair bit of forth and I've not seen c" used. The usual string printing operator is ." .
- mananaysiempre 2y agoCounted (“Pascal”) strings are rare nowadays so C" is not often used. Its addr len equivalent is S" and that one is fairly common in string manipulation code.
- kragen 2y agoRight, c" is for when you want to pass a literal string to some other word, not print it. But I agree that it's not very common, because you normally use s" for that, which leaves the address and length on the stack, while c" leaves just an address on the stack, pointing to a one-byte count field followed by the bytes. I think adding c" in Forth-83 (and renaming " to s") was a mistake, and it would have been better to deprecate the standard words that expect or produce such counted strings, other than count itself. See https://forth-standard.org/standard/alpha https://forth-standard.org/standard/alpha, https://forth-standard.org/standard/core/Cq https://forth-standard.org/standard/core/Cq, https://forth-standard.org/standard/core/COUNT https://forth-standard.org/standard/core/COUNT, and https://forth-standard.org/standard/core/Sq https://forth-standard.org/standard/core/Sq. You can easily add new string and comment syntaxes to Forth, though. For example, you can add BCPL-style // comments to end of line with this line of code in, I believe, all standard Forths, though I've only tested it in GForth: : // 10 word drop ; immediate Getting it to work in block files requires more work but is still only a few lines of code. The standard word \ does this, and see \ decompiles the GForth implementation as : \ blk @ IF >in @ c/l / 1+ c/l * >in ! EXIT THEN source >in ! drop ; immediate This kind of thing was commonly done for text editor commands, for example; you might define i as a word that reads text until the end of the line and inserts it at the current position in the editor, rather than discarding it like my // above. Among other things, the screen editor in F83 does exactly that. So, as with Perl, PostScript, TeX, m4, and Lisps that support readmacros, you can't lex Forth without executing it.