This section starts with a glossary of Forth words and ends with a set of examples.
bl– c-char core “b-l”
c-char is the character value for a space.
space– core “space”
Display one space.
spacesu – core “spaces”
Display n spaces.
emitc – core “emit”
Display the character associated with character value c.
toupperc1 – c2 gforth “toupper”
If c1 is a lower-case character (in the current locale), c2 is the equivalent upper-case character. All other characters are unchanged.
."compilation ’ccc"’ – ; run-time – core “dot-quote”
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&interpretation "ccc<paren>" – core-ext “dot-paren”
Compilation and interpretation semantics: Parse a string ccc
delimited by a
) (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”
.", but translates C-like \-escape-sequences (see
typec-addr u – core “type”
If u>0, display u characters from a string starting with the character stored at c-addr.
typewhiteaddr n – gforth “typewhite”
Like type, but white space is printed instead of the characters.
cr– core “c-r”
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 is at the start
of a piece of text; e.g.,
cr ." hello, world".
S"compilation ’ccc"’ – ; run-time – c-addr u core,file “s-quote”
Compilation: Parse a string ccc delimited by a
(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
evaluate them; then the leak is not bounded
by the size of the interpreted files and you may want to
free the strings. Forth-2012 only guarantees two buffers of
80 characters each, so in standard programs you should assume that the
string lives only until the next-but-one
s\"compilation ’ccc"’ – ; run-time – c-addr u gforth “s-backslash-quote”
S", but translates C-like \-escape-sequences, as
\a BEL (alert),
\e ESC (not in
numerical character value (non-standard),
hex numerical character value (standard only with two digits); a
\ before any other character is reserved.
C"compilation "ccc<quote>" – ; run-time – c-addr core-ext “c-quote”
Compilation: parse a string ccc delimited by a
(double quote). At run-time, return c-addr which
specifies the counted string ccc. Interpretation
semantics are undefined.
char’<spaces>ccc’ – c core “char”
Skip leading spaces. Parse the string ccc and return c, the display code representing the first character of ccc.
[Char]compilation ’<spaces>ccc’ – ; run-time – c core “bracket-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.
As an example, consider the following text, stored in a file test.fs:
.( 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