Print double quotes in Forth

The word ." prints a string. More precisely it compiles the (.") and the string up to the next " in the currently compiled word.

But how can I print

That's the "question".

with Forth?


  • In a Forth-2012 System (e.g. Gforth) you can use string literals with escaping via the word s\" as:

    : foo ( -- ) s\" That's the \"question\"." type ;

    In a Forth-94 system (majority of standard systems) you can use arbitrary parsing and the word sliteral as:

    : foo ( -- ) [ char | parse That's the "question".| ] sliteral type ;

    A string can be also extracted up to the end of the line (without printable delimiter); a multi-line string can be extracted too.

    Specific helpers for particular cases can be easily defined. For example, see the word s$ for string literals that are delimited by any arbitrary printable character, e.g.:

      s$ `"test" 'passed'` type