Commit e8ca62aa authored by paysan's avatar paysan

Last round of Leo's proofreading

parent a37ac40b
......@@ -274,28 +274,28 @@ VARIABLE MARKER
: ;AND COMPILE EXIT HERE MARKER @ ! ; IMMEDIATE
: UNDO ['] NOTHING [COMPILE] ' ! ;
( 238 )
( The code in this screen is in the public domain.)
\end{Screen}
\vfill
\begin{Screen}
( TODDLER: Example of DOER/MAKE 12/01/83 )
DOER WHY?
DOER ANSWER
: RECITAL
CR ." Your daddy is standing on the table. Ask him 'WHY?' "
MAKE WHY? ." To change the light bulb."
MAKE ANSWER ." To change the light bulb."
BEGIN
MAKE WHY? ." Because it's burned out."
MAKE WHY? ." Because it was old."
MAKE WHY? ." Because we put it in there a long time ago."
MAKE WHY? ." Because it was dark!"
MAKE WHY? ." Because it was night time!!"
MAKE WHY? ." Stop saying WHY?"
MAKE WHY? ." Because it's driving me crazy."
MAKE WHY? ." Just let me change this light bulb!"
F UNTIL ;
: WHY? CR WHY? QUIT ;
MAKE ANSWER ." Because it's burned out."
MAKE ANSWER ." Because it was old."
MAKE ANSWER ." Because we put it in there a long time ago."
MAKE ANSWER ." Because it was dark!"
MAKE ANSWER ." Because it was night time!!"
MAKE ANSWER ." Stop saying WHY?"
MAKE ANSWER ." Because it's driving me crazy."
MAKE ANSWER ." Just let me change this light bulb!"
FALSE UNTIL ;
: WHY? CR ANSWER QUIT ;
\end{Screen}
\index{D!DOER/MAKE|)}
\vfill
......@@ -68,7 +68,7 @@ can be defined as:
(\Forth{}'s control words such as \forth{IF} and \forth{UNTIL} interpret
zero as ``false'' and any non-zero value as ``true.'' Before \Forth{}
'83, the convention was to indicate ``true'' with the value $1$. Starting
with \Forth{} '83, however, ``true'' is indicated with hex \code{FF},
with \Forth{} '83, however, ``true'' is indicated with hex \code{FFFF},
which is the signed number $-1$ (all bits set).
\forthb{WITHIN}\index{W!WITHIN} can be defined in high level like this:
......@@ -76,6 +76,11 @@ which is the signed number $-1$ (all bits set).
: WITHIN ( n lo hi+1 -- ?)
>R 1- OVER < SWAP R> < AND ;
\end{Code}
or
\begin{Code}
: WITHIN ( n lo hi+1 -- ?)
OVER - >R - R> U< ;
\end{Code}
\section{From \Chap{8}}
......
......@@ -45,23 +45,23 @@ or to allocate growing downward:
\ifeightyfour\begin{enumerate}
\item\fi Our solution is as follows:
\begin{Code}
\ CARDS Shuffle 6-20-83
\ CARDS Shuffle 6-20-83
52 CONSTANT #CARDS
CREATE DECK #CARDS ALLOT \ one card per byte
: INIT-DECK
#CARDS 0 DO I DECK I + C! LOOP ;
CREATE DECK #CARDS ALLOT \ one card per byte
: CARD ( i -- adr) DECK + ;
: INIT-DECK #CARDS 0 DO I I CARD C! LOOP ;
INIT-DECK
: 'CSWAP ( a1 a2 -- ) \ swap bytes at a1 and a2
2DUP C@ SWAP C@ ROT C! SWAP C! ;
: SHUFFLE \ shuffle deck of cards
#CARDS 0 DO DECK I + DECK #CARDS CHOOSE +
'CSWAP LOOP ;
#CARDS 0 DO I CARD #CARDS CHOOSE CARD 'CSWAP
LOOP ;
\end{Code}
\ifeightyfour\end{enumerate}\fi
\section{\Chap{8}}
\ifeightyfour\begin{enumerate}
\item\fi This will work:
\item This will work:
\begin{Code}
20 CHOOSE 2 CHOOSE IF NEGATE THEN
\end{Code}
......@@ -69,7 +69,11 @@ But this is simpler:
\begin{Code}
40 CHOOSE 20 -
\end{Code}
\ifeightyfour\end{enumerate}\fi
\end{enumerate}\else
\begin{Code}
: DIRECTION ( n|-n|0 -- 1|-1|0) DUP IF 0< 1 OR THEN ;
\end{Code}
\fi
%% Note: The question was random number between 0 and 19, and -20 and 0.
%% The first solution gives between 0 and 19, or -19 and 0.
......
......@@ -236,7 +236,7 @@ superstring array&``name''&``COLORS''\\
--&dash; not\\
+&plus\\
=&equals\\
\{ \}&faces (traditionally called ``curly brackets'')\\
\{ \}&braces (traditionally called ``curly brackets'')\\
{[} {]}&square brackets\\
``&quote\\
'&as prefix: tick; as suffix: prime\\
......
......@@ -647,7 +647,7 @@ and gets replaced with a black one.
Your entire manual is obsolete. You could have avoided the
obsolescence by using the term ``Shipping Clerk'' instead of the name
``Jay,'' the terms ``Bookkeeping Dept. copy and'' ``Shipping Dept. copy''
``Jay,'' the terms ``Bookkeeping Dept. copy'' and ``Shipping Dept. copy''
instead of ``blue'' and ``orange,'' etc.
This example illustrates that in order to maintain correctness in the
......@@ -1308,7 +1308,7 @@ numbers on your terminal instead of controlling stepper motors. They
may print their own names just to let you know they've executed. They
may do nothing at all.
Using this philosophy you can write a simple by testable version of
Using this philosophy you can write a simple but testable version of
your application, then successively change and refine it until you
reach your goal.
......@@ -1369,7 +1369,7 @@ But in large applications, \Forth{} comes very close to the speed of
assembler. Here are three reasons:
First and foremost, \Forth{} is simple. \Forth{}'s use of a data stack%
\index{D!Data stacks}%
\index{D!Data stacks}
greatly reduces the performance cost of passing arguments from word to
word. In most languages, passing arguments between modules is one of
the main reasons that the use of subroutines inhibits performance.
......
......@@ -759,9 +759,9 @@ these words. It merely recognizes certain words as ``immediate'' and
executes them, letting them do their own work. (See \emph{Starting
\Forth{}}, Chapter Eleven, ``How to Control the Colon Compiler.'')
The compiler doesn't even ``look for'' semicolon to know when to
stop compiling. Instead it executes semicolon, allowing it to do the work
of ending the definition and shutting off the compiler.
The compiler doesn't even ``look for'' semicolon to know when to stop
compiling. Instead it \emph{executes} semicolon, allowing it to do the
work of ending the definition and shutting off the compiler.
There are two tremendous advantages to this approach. First, the
compiler is so simple it can be written in a few lines of code. Second,
......@@ -1172,7 +1172,7 @@ we'll get a 7 and a 3 on the stack (the three---being the quotient---is on
top.)
But these observations raise a question: What about below ten, where there
is no decimal digit? Is this a special case? Well, if we consider that
is no ten's place? Is this a special case? Well, if we consider that
each ``X'' represents ten, then the absence of ``X'' represents zero. So
it's \emph{not} a special case. Our algorithm works, even for numbers less
than ten.
......@@ -1598,8 +1598,8 @@ CREATE ROMANS ( ones) ASCII I C, ASCII V C,
( thousands) ASCII M C,
\end{Code}
Note: This use of \forthb{ASCII} requires that \forthb{ASCII} be
``\forthb{STATE}-dependent'' (see \App{C}). If you don't have \forthb{ASCII},
or if it is not state-dependent, use:
``\forthb{STATE}-dependent'' (see \App{C}). If the word \forthb{ASCII}
is not defined in your system, or if it is not state-dependent, use:
\begin{Code}
CREATE ROMANS 73 C, 86 C, 88 C, 76 C,
......@@ -1632,7 +1632,7 @@ Now we can find our way to any ``arm position'' by adding the contents of
\forth{ROMANS}:
\begin{Code}
: COLUMN ( -- adr of column) ROMANS COLUMN# @ + ;
: COLUMN ( -- adr-of-column) ROMANS COLUMN# @ + ;
\end{Code}
Let's see if we can implement one of the words to display a symbol. We'll
start with \forth{ONER}.
......@@ -1732,13 +1732,13 @@ CREATE ROMANS ( ones) ASCII I C, ASCII V C,
( tens) ASCII X C, ASCII L C,
( hundreds) ASCII C C, ASCII D C,
( thousands) ASCII M C,
VARIABLE COLUMN# ( current offset)
VARIABLE COLUMN# ( current_offset)
: ONES O COLUMN# ! ;
: TENS 2 COLUMN# ! ;
: HUNDREDS 4 COLUMN# ! ;
: THOUSANDS 6 COLUMN# ! ;
: COLUMN ( -- address of column) ROMANS COLUMN# @ + ;
: COLUMN ( -- address-of-column) ROMANS COLUMN# @ + ;
\end{Screen}
......@@ -1749,9 +1749,9 @@ VARIABLE COLUMN# ( current offset)
: FIVER 1 .SYMBOL ;
: TENER 2 .SYMBOL ;
: ONERS ( # of oners -- )
: ONERS ( #-of-oners -- )
?DUP IF O DO ONER LOOP THEN ;
: ALMOST ( quotient of 5 / -- )
: ALMOST ( quotient-of-5/ -- )
ONER IF TENER ELSE FIVER THEN ;
: DIGIT ( digit -- )
5 /MOD OVER 4 = IF ALMOST DROP ELSE IF FIVER THEN
......
......@@ -437,7 +437,7 @@ don't recommend it.%
\index{L!Listing organization|)}
%Page 143 in first edition.
\section{An Alternative to Screens: Source in Named Files}%
\subsection{An Alternative to Screens: Source in Named Files}%
\index{N!Named files, storing source code in|(}
\index{F!File-based system|(}%
......@@ -657,7 +657,7 @@ for the continuing screens are indented.%
\begin{tip}
Begin all definitions at the left edge of the screen, and define only
one word per lines.
one word per line.
\end{tip}
%! There should be no page breaks between the text and code
\noindent \emph{Bad:}
......@@ -1277,7 +1277,7 @@ On the other hand, a word's purpose can often be described in terms of
its stack-effect comment. You rarely need both a stack comment and a
purpose comment. For instance:
\begin{Code}
: SPACES ( #)
: SPACES ( #) ... ;
\end{Code}
%Page 157 in first edition.
or
......@@ -1343,7 +1343,7 @@ comment its run-time behavior separately, following the word
\end{tip}
For instance,
\begin{Code}
: CONSTANT ( n )
: CONSTANT ( n ) CREATE ,
DOES> ( -- n) @ ;
\end{Code}
The stack-effect comment for the run-time (child's) behavior
......
......@@ -661,7 +661,7 @@ VARIABLE CURSOR
The rest of your code can remain intact.
\begin{tip}
Factor calculations algorithms out of definitions that display results.
Factor functions out of definitions that display results.
\end{tip}
This is really a question of decomposition.
......
......@@ -171,7 +171,7 @@ we have four elements on the stack.
At this point, the first resort is usually the return stack:
\begin{Code}
BLK @ DUP >R + 1+ SWAP R> + +
BLK @ DUP >R + 1+ SWAP R> +
\end{Code}
(See ``The Stylish Return Stack,'' coming up next.) Here we've \forthb{DUP}ed
``blk,'' saving one copy on the return stack and adding the other copy to
......@@ -478,7 +478,7 @@ conditions.
\item In factoring definitions, watch out that one part doesn't contain
one return stack operator, and the other its counterpart.
\item If used inside a \forthb{DO }\forthb{LOOP}, return stack operators
must by symmetrical within the loop, and \forthb{I} is no longer valid in
must be symmetrical within the loop, and \forthb{I} is no longer valid in
code bounded by \forthb{>R} and \forthb{R>}.
\end{enumerate}
\end{tip}
......
......@@ -587,8 +587,8 @@ for equality against a number on the stack. In the instance of
efficient to use the integer to calculate an offset and directly jump to
the right code.
In the case of our Tiny Editor, later in this chapter, we have not but
two dimensions of possibilities. The case statement doesn't match that
In the case of our Tiny Editor, later in this chapter, we have not one, but
two, dimensions of possibilities. The case statement doesn't match that
problem either.
Personally, I consider the case statement an elegant solution to a
......@@ -786,7 +786,7 @@ is equivalent to the simpler statement
\begin{Code}
( ? ) n AND
\end{Code}
Again, the secret is that ``false'' is represented by $-1$ (all ones) in
Again, the secret is that ``true'' is represented by $-1$ (all ones) in
'83 \Forth{} systems. \forthb{AND}ing ``$n$'' with the flag will either
produce ``$n$'' (all bits intact) or ``$0$'' (all bits cleared).
......@@ -1218,7 +1218,7 @@ Structured Exits.'')%
\index{T!Two-dimensional decision table|)}%
\program{editor5}
\section{Decision Tables for Speed}
\subsection{Decision Tables for Speed}
We've stated that if you can calculate a value instead of looking it up in a
table, you should do so. The exception is where the requirements for
......@@ -1229,7 +1229,7 @@ Here is an example that computes powers of two to 8-bit precision:
\begin{Code}
CREATE TWOS
1 C, 2 C, 4 C, 8 C, 16 C, 32 C,
: 2** ( n -- 2 to the n)
: 2** ( n -- 2-to-the-n)
TWOS + C@ ;
\end{Code}
Instead of computing the answer by multiplying two times itself ``$n$''
......@@ -1442,7 +1442,7 @@ out a control structure using this technique:
\Forth{} allows us to alter the control flow by directly manipulating the
return stack. (If in doubt, see \emph{Starting \Forth{}}, Chapter Nine.)
Indiscreet application of this trick can lead to unstructured code with nasty
side effect. But the disciplined use of the structured exit can actually
side effects. But the disciplined use of the structured exit can actually
simplify code, and thereby improve readability and maintainability.
\begin{interview}
......@@ -1538,7 +1538,7 @@ We can introduce the word \forth{LEAP} (see \App{C}), which will work
like \forthb{EXIT} (it will simulate a semicolon). Now we can write:
\begin{Code}
: 'FUNCTION ( key -- adr of match )
: 'FUNCTION ( key -- adr-of-match )
'NOMATCH FUNCTIONS DO DUP I @ = IF DROP I LEAP
THEN /KEY +LOOP DROP 'NOMATCH ;
\end{Code}
......@@ -1876,7 +1876,8 @@ Dimensions} II/3, p. 37.
\section{For Further Thinking}
\ifeightyfour\begin{enumerate}
\item\fi You have the word \forth{CHOOSE} which takes an argument ``$n$''
\item
You have the word \forth{CHOOSE} which takes an argument ``$n$''
and returns a random number between 0 and $n-1$. The result is always
positive or zero. You can use \forth{CHOOSE} to produce a flag; the
phrase
......@@ -1886,7 +1887,12 @@ phrase
produces a random flag of zero or one (false or true).
%%!!! this is not the second question, there is no question above
\ifeightyfour\item\fi
\item
Write a phrase to choose a number at random between 0 and 19 (inclusive)
\emph{or} between $-20$ and 0.
\ifeightyfour\end{enumerate}\fi
\end{enumerate}\else
%% replacement problem
Define the word \forth{DIRECTION}, which returns either 1,
$-1$, or 0, depending on whether the input argument is non-zero
positive, negative, or zero, respectively.
\fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment