Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print double quotes in Forth

Tags:

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?

like image 502
harper Avatar asked Jan 24 '23 06:01

harper


2 Answers

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
like image 106
ruvim Avatar answered Jan 28 '23 11:01

ruvim


Old school:

34 emit

Output:

"

Using gforth:

: d 34 emit ;
cr ." That's the " d ." question" d ." ." cr 

Output:

That's the "question".
like image 23
agc Avatar answered Jan 28 '23 11:01

agc