-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathappendixc.tex
More file actions
99 lines (90 loc) · 2.89 KB
/
appendixc.tex
File metadata and controls
99 lines (90 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
%% Thinking Forth
%% Copyright (C) 2004 Leo Brodie
%% Initial transcription by Ed Beroset
%%
%% Chapter: Appendix C, Other Utilities Described in This Book
\Chapmark{C}
\chapter{Other~Utilities Described in~This~Book}
\initial This appendix is here to help you define some of the words
referred to in this book that may not exist in your system.
Definitions are given in \Forth{}-83 Standard.
\section{From \Chap{4}}
A definition of \forthb{ASCII}\index{A!ASCII} that will work in '83
Standard is:
\begin{Code}
: ASCII ( -- c) \ Compile: c ( -- )
\ Interpret: c ( -- c)
bl word 1+ c@ state @
IF [compile] Literal THEN ; immediate
\end{Code}
\section{From \Chap{5}}
The word \forthb{\bs}\index{S!Skip commands} can be defined as:
\begin{Code}
: \ ( skip rest of line)
>in @ 64 / 1+ 64 * >in ! ; immediate
\end{Code}
If you decide not to use \forthb{EXIT} to terminate a screen, you can
define \forthb{\bs S} as:
\begin{Code}
: \S 1024 >in ! ;
\end{Code}
\index{F!FH|(}%
The word \forthb{FH} can be defined simply as:
\begin{Code}
: FH \ ( offset -- offset-block) "from here"
blk @ + ;
\end{Code}
This factoring allows you to use \forth{FH} in many ways, e.g.:
\begin{Code}
: TEST [ 1 FH ] Literal load ;
\end{Code}
or
\begin{Code}
: see [ 2 FH ] Literal list ;
\end{Code}
A slightly more complicated version of \forth{FH} also lets you edit or
load a screen with a phrase such as ``\forth{14 FH LIST},'' relative to
the screen that you just listed (\forth{SCR}):
\begin{Code}
: FH \ ( offset -- offset-block) "from here"
blk @ ?dup 0= IF scr @ THEN + ;
\end{Code}
\index{F!FH|)}
\forthb{BL}\index{B!Blank space (BL)} is a simple constant:
\begin{Code}
32 Constant bl
\end{Code}
\forthb{TRUE}\index{T!TRUE} and \forthb{FALSE}\index{F!FALSE}
can be defined as:
\begin{Code}
0 Constant false
-1 Constant true
\end{Code}
(\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{FFFF},
which is the signed number $-1$ (all bits set).
\forthb{WITHIN}\index{W!WITHIN} can be defined in high level like this:
\begin{Code}
: 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}}
The implementation of \forthb{LEAP}\index{L!LEAP} will depend on how your
system implements \forthb{DO} \forthb{LOOP}s. If \forthb{DO} keeps two
items on the return stack (the index and the limit), \forthb{LEAP} must
drop both of them plus one more return-stack item to exit:
\begin{Code}
: LEAP r> r> 2drop r> drop ;
\end{Code}
If \forthb{DO} keeps \emph{three} items on the return stack, it must be
defined:
\begin{Code}
: LEAP r> r> 2drop r> r> 2drop ;
\end{Code}