version 1.170, 2007/01/21 17:29:54
|
version 1.171, 2007/02/08 14:07:33
|
Line 1251 the command line history with cursor key
|
Line 1251 the command line history with cursor key
|
@section Syntax |
@section Syntax |
@cindex syntax tutorial |
@cindex syntax tutorial |
|
|
A @dfn{word} is a sequence of arbitrary characters (expcept white |
A @dfn{word} is a sequence of arbitrary characters (except white |
space). Words are separated by white space. E.g., each of the |
space). Words are separated by white space. E.g., each of the |
following lines contains exactly one word: |
following lines contains exactly one word: |
|
|
Line 1597 see +
|
Line 1597 see +
|
@cindex stack-effect comments, tutorial |
@cindex stack-effect comments, tutorial |
@cindex --, tutorial |
@cindex --, tutorial |
By convention the comment after the name of a definition describes the |
By convention the comment after the name of a definition describes the |
stack effect: The part in from of the @samp{--} describes the state of |
stack effect: The part in front of the @samp{--} describes the state of |
the stack before the execution of the definition, i.e., the parameters |
the stack before the execution of the definition, i.e., the parameters |
that are passed into the colon definition; the part behind the @samp{--} |
that are passed into the colon definition; the part behind the @samp{--} |
is the state of the stack after the execution of the definition, i.e., |
is the state of the stack after the execution of the definition, i.e., |
Line 1787 If one parameter usually requires only a
|
Line 1787 If one parameter usually requires only a
|
a constant), pass it on the top of the stack. Conversely, parameters |
a constant), pass it on the top of the stack. Conversely, parameters |
that usually require a long sequence of code to compute should be passed |
that usually require a long sequence of code to compute should be passed |
as the bottom (i.e., first) parameter. This makes the code easier to |
as the bottom (i.e., first) parameter. This makes the code easier to |
read, because reader does not need to keep track of the bottom item |
read, because the reader does not need to keep track of the bottom item |
through a long sequence of code (or, alternatively, through stack |
through a long sequence of code (or, alternatively, through stack |
manipulations). E.g., @code{!} (store, @pxref{Memory}) expects the |
manipulations). E.g., @code{!} (store, @pxref{Memory}) expects the |
address on top of the stack because it is usually simpler to compute |
address on top of the stack because it is usually simpler to compute |
Line 1879 An @code{if}-structure looks like this:
|
Line 1879 An @code{if}-structure looks like this:
|
@code{if} takes a flag from the stack. If the flag is non-zero (true), |
@code{if} takes a flag from the stack. If the flag is non-zero (true), |
the following code is performed, otherwise execution continues after the |
the following code is performed, otherwise execution continues after the |
@code{endif} (or @code{else}). @code{<} compares the top two stack |
@code{endif} (or @code{else}). @code{<} compares the top two stack |
elements and prioduces a flag: |
elements and produces a flag: |
|
|
@example |
@example |
1 2 < . |
1 2 < . |
Line 1950 Gforth supports all combinations of the
|
Line 1950 Gforth supports all combinations of the
|
these combinations are standard (for details see the standard, |
these combinations are standard (for details see the standard, |
@ref{Numeric comparison}, @ref{Floating Point} or @ref{Word Index}). |
@ref{Numeric comparison}, @ref{Floating Point} or @ref{Word Index}). |
|
|
You can use @code{and or xor invert} can be used as operations on |
You can use @code{and or xor invert} as operations on canonical flags. |
canonical flags. Actually they are bitwise operations: |
Actually they are bitwise operations: |
|
|
@example |
@example |
1 2 and . |
1 2 and . |
Line 2078 Reference: @ref{Simple Loops}.
|
Line 2078 Reference: @ref{Simple Loops}.
|
|
|
@example |
@example |
: ^ ( n1 u -- n ) |
: ^ ( n1 u -- n ) |
\ n = the uth power of u1 |
\ n = the uth power of n1 |
1 swap 0 u+do |
1 swap 0 u+do |
over * |
over * |
loop |
loop |