Node:Displaying characters and strings, Next:Input, Previous:String Formats, Up:Other I/O
This section starts with a glossary of Forth words and ends with a set
c-char is the character value for a space.
bl-- c-char core ``b-l''
Display one space.
space-- core ``space''
Display n spaces.
spacesu -- core ``spaces''
Display the character associated with character value c.
emitc -- core ``emit''
If c1 is a lower-case character (in the current locale), c2 is the equivalent upper-case character. All other characters are unchanged.
toupperc1 -- c2 gforth ``toupper''
Compilation: Parse a string ccc delimited by a " (double quote). At run-time, display the string. Interpretation semantics for this word are undefined in ANS Forth. Gforth's interpretation semantics are to display the string. This is the simplest way to display a string from within a definition; see examples below.
."compilation 'ccc"' -- ; run-time -- core ``dot-quote''
Compilation and interpretation semantics: Parse a string ccc delimited by a
.(compilation&interpretation "ccc<paren>" -- core-ext ``dot-paren''
)(right parenthesis). Display the string. This is often used to display progress information during compilation; see examples below.
.\"compilation 'ccc"' -- ; run-time -- gforth ``dot-backslash-quote''
If u>0, display u characters from a string starting with the character stored at c-addr.
typec-addr u -- core ``type''
Like type, but white space is printed instead of the characters.
typewhiteaddr n -- gforth ``typewhite''
Output a newline (of the favourite kind of the host OS). Note that due to the way the Forth command line interpreter inserts newlines, the preferred way to use
cr-- core ``c-r''
cris at the start of a piece of text; e.g.,
cr ." hello, world".
Position the cursor so that subsequent text output will take place at column u1, row u2 of the display. (column 0, row 0 is the top left-hand corner of the display).
at-xyu1 u2 -- facility ``at-x-y''
Clear the display and set the cursor to the top left-hand corner.
page-- facility ``page''
Compilation: Parse a string ccc delimited by a
S"compilation 'ccc"' -- ; run-time -- c-addr u core,file ``s-quote''
"(double quote). At run-time, return the length, u, and the start address, c-addr of the string. Interpretation: parse the string as before, and return c-addr, u. Gforth
allocates the string. The resulting memory leak is usually not a problem; the exception is if you create strings containing
evaluatethem; then the leak is not bounded by the size of the interpreted files and you may want to
freethe strings. ANS Forth only guarantees one buffer of 80 characters, so in standard programs you should assume that the string lives only until the next
s\"compilation 'ccc"' -- ; run-time -- c-addr u gforth ``s-backslash-quote''
S", but translates C-like \-escape-sequences into single characters. See
Compilation: parse a string ccc delimited by a
C"compilation "ccc<quote>" -- ; run-time -- c-addr core-ext ``c-quote''
"(double quote). At run-time, return c-addr which specifies the counted string ccc. Interpretation semantics are undefined.
Skip leading spaces. Parse the string ccc and return c, the display code representing the first character of ccc.
char'<spaces>ccc' -- c core ``char''
Compilation: skip leading spaces. Parse the string ccc. Run-time: return c, the display code representing the first character of ccc. Interpretation semantics for this word are undefined.
[Char]compilation '<spaces>ccc' -- ; run-time -- c core ``bracket-char''
As an example, consider the following text, stored in a file
.( text-1) : my-word ." text-2" cr .( text-3) ; ." text-4" : my-char [char] ALPHABET emit char emit ;
When you load this code into Gforth, the following output is generated:
include test.fs <RET> text-1text-3text-4 ok
text-3are displayed because
.(is an immediate word; it behaves in the same way whether it is used inside or outside a colon definition.
text-4is displayed because of Gforth's added interpretation semantics for
text-2is not displayed, because the text interpreter performs the compilation semantics for
."within the definition of
Here are some examples of executing
my-word <RET> text-2 ok my-char fred <RET> Af ok my-char jim <RET> Aj ok
text-2is displayed because of the run-time behaviour of
[char]compiles the "A" from "ALPHABET" and puts its display code on the stack at run-time.
emitalways displays the character when
charparses a string at run-time and the second
emitdisplays the first character of the string.
see my-charyou can see that
[char]discarded the text "LPHABET" and only compiled the display code for "A" into the definition of