Skip to content

Commit d8e8092

Browse files
James CashChris Double
James Cash
authored and
Chris Double
committed
Replacing '...' with `...' for better-looking quotes, as well as minor spelling fixes, and unescaped %'s
1 parent f297ae0 commit d8e8092

14 files changed

+285
-279
lines changed

cells.tex

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ \chapter{Cells}\label{cells}
55
functional reactive programming system.
66

77
\section{Models}
8-
To have a gadget dynamically updated it must reference a 'model' which
8+
To have a gadget dynamically updated it must reference a `model' which
99
wraps the value to be displayed. Whenever the data wrapped by the
1010
model is changed, a sequence of connected objects are notified of the
1111
change.
@@ -68,7 +68,7 @@ \section{Gadgets and Models}
6868

6969
\section{Updating time example}
7070

71-
In this example I create a global value called 'time' that holds a
71+
In this example I create a global value called `time' that holds a
7272
model wrapping the current date and time:
7373

7474
\begin{verbatim}
@@ -96,7 +96,7 @@ \section{Updating time example}
9696
and sets the model's value to it. An alarm is added to do this every second.
9797

9898
We can confirm that this value is updating by getting the value of
99-
the 'time' variable and see that it changes between calls:
99+
the `time' variable and see that it changes between calls:
100100

101101
\begin{alltt}
102102
USE: calendar.format

channels.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ \chapter{Channels}\label{channels}
2525
data. There can also be multiple receivers blocking. A random one is
2626
selected to receive the data when a sender becomes available.
2727

28-
Here is the 'counter' example ported from NewSqueak:
28+
Here is the `counter' example ported from NewSqueak:
2929

3030
\begin{verbatim}
3131
USING: channels concurrency ;

compilers.tex

+48-45
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ \chapter{Compilers and Interpreters}\label{compilers}
2020
interpreter like Rhino, or in a web browser.
2121

2222
To more easily re-use the AST across the two examples I added the
23-
ability to pattern match on tuples to the 'match' contrib
23+
ability to pattern match on tuples to the `match' contrib
2424
library. This can be obtained from the standard Factor git
2525
repository:
2626
\begin{verbatim}
2727
git clone git://factorcode.org/git/factor.git
2828
\end{verbatim}
2929

3030

31-
The factor 'latest' boot images can be used to bootstrap from this
31+
The factor `latest' boot images can be used to bootstrap from this
3232
repository. The instructions on how to do this are on
3333
factorcode.org. For an Intel x86 linux machine the steps would be:
3434

@@ -41,20 +41,20 @@ \chapter{Compilers and Interpreters}\label{compilers}
4141
\end{verbatim}
4242

4343
The examples here should also work with the released Factor 0.85 as
44-
long as you replace 'contrib/match/match.factor' with the version from
45-
my repository. To load the 'match' library in Factor use:
44+
long as you replace `contrib/match/match.factor' with the version from
45+
my repository. To load the `match' library in Factor use:
4646

4747
\begin{verbatim}
4848
USE: match
4949
\end{verbatim}
5050

51-
In the Factor code snippets below I use '=>' to show the result of
51+
In the Factor code snippets below I use `=>' to show the result of
5252
running Factor words. You shouldn't actually type that. Instead the
53-
result will be shown on the Factor stack or you can use '.' to print
53+
result will be shown on the Factor stack or you can use `.' to print
5454
it.
5555

5656
The code for the examples in this post can be downloaded from
57-
interpreter.factor. If you copy it into the 'contrib' directory of
57+
interpreter.factor. If you copy it into the `contrib' directory of
5858
your Factor installation you can load it with:
5959

6060

@@ -87,8 +87,8 @@ \chapter{Compilers and Interpreters}\label{compilers}
8787

8888
Basically we have literal values, which in this example are
8989
integers. These can be incremented and tested to see if they are
90-
zero. A 'pair' can be created and the first and second elements
91-
obtained from the pair. An 'if' expression is available for testing
90+
zero. A `pair' can be created and the first and second elements
91+
obtained from the pair. An `if' expression is available for testing
9292
an expression and evaluating a true or false clause. These are
9393
represented using Factor tuples:
9494

@@ -103,28 +103,28 @@ \chapter{Compilers and Interpreters}\label{compilers}
103103
\end{verbatim}
104104

105105
I used the same names for the types and elements as the example but
106-
changed 'if' to 'iff' to prevent clashing with Factor's standard 'if'
106+
changed `if' to `iff' to prevent clashing with Factor's standard `if'
107107
word. An example tree can be created that is the increment of the
108108
number 5 with:
109109

110110
\begin{verbatim}
111111
5 <lit> <inc>
112112
\end{verbatim}
113113

114-
When evaluated this should produce the result '6'.
114+
When evaluated this should produce the result `6'.
115115

116116
The interpreter implementation that uses pattern matching uses
117-
'match-cond'. This requires match variables to be set up which can be
117+
`match-cond'. This requires match variables to be set up which can be
118118
used to destructure sequences and tuples. For example:
119119

120120
\begin{verbatim}
121121
5 <lit> T{ lit f ?t } match [ ?t ] bind => 5
122122
\end{verbatim}
123123

124-
'T{ lit f 123 }' is the Factor syntax for a tuple. It creates a tuple
124+
`T{ lit f 123 }' is the Factor syntax for a tuple. It creates a tuple
125125
at parse time and the actual object is stored in the word. This is
126126
different from '123 <lit>' which will produce the literal object at
127-
runtime. '?t' is a matching variable and the 'match' and 'match-cond'
127+
runtime. `?t' is a matching variable and the `match' and `match-cond'
128128
words use these to destructure matching elements of tuples and
129129
sequences. The match variable can then be used to get the actual value
130130
obtained. For more on the Factor pattern matching system you can read
@@ -179,15 +179,15 @@ \chapter{Compilers and Interpreters}\label{compilers}
179179
42 <lit> 8 <lit> 9 <lit> <pair> <pair> <snd> <fst> <pair> ;
180180
\end{verbatim}
181181

182-
Running the 'eval1' word on this produces the answer, { 7 8 }:
182+
Running the `eval1' word on this produces the answer, { 7 8 }:
183183

184184
\begin{verbatim}
185185
driver eval1 => { 7 8 }
186186
\end{verbatim}
187187

188-
Although 'eval1' is quite short and easy to understand it has a
188+
Although `eval1' is quite short and easy to understand it has a
189189
disadvantage in that to extend it with new AST types you need to
190-
modify the 'eval1' word. Using the Factor OO generic word system you
190+
modify the `eval1' word. Using the Factor OO generic word system you
191191
extend the interpreter without having to modify existing code. Here's
192192
a generic word approach to the interpreter:
193193

@@ -203,24 +203,24 @@ \chapter{Compilers and Interpreters}\label{compilers}
203203
M: snd eval2 ( a -- a ) snd-t eval2 second ;
204204
\end{verbatim}
205205

206-
The 'M:' word is used to define a method for a generic word. This is
206+
The `M:' word is used to define a method for a generic word. This is
207207
similar to how generic functions and methods work in CLOS and
208208
Dylan. When a generic word is called the actual method invoked is
209-
based on the topmost item of the stack. The first symbol past the 'M:'
209+
based on the topmost item of the stack. The first symbol past the `M:'
210210
is the type of that object that that method is for. The second is the
211211
name of the generic word the method will be added too. The rest of the
212212
definitions should be reasonably clear - they break apart the tuples
213-
and return results or call 'eval2' recursively. 'eval2' produces the
214-
same result as 'eval1':
213+
and return results or call `eval2' recursively. `eval2' produces the
214+
same result as `eval1':
215215

216216
\begin{verbatim}
217217
driver eval2 => { 7 8 }
218218
\end{verbatim}
219219

220220
Which approach to use is really personal preference. Of the two,
221-
'eval2' is the most efficient. This is because methods can be compiled
222-
in Factor whereas the current implementation of 'match-cond' cannot
223-
be. So 'eval1' will run in the Factor interpreter whereas 'eval2' will
221+
`eval2' is the most efficient. This is because methods can be compiled
222+
in Factor whereas the current implementation of `match-cond' cannot
223+
be. So `eval1' will run in the Factor interpreter whereas `eval2' will
224224
be compiled to native code. This can be seen by trying to compile the
225225
examples and running a timed test:
226226

@@ -233,7 +233,7 @@ \chapter{Compilers and Interpreters}\label{compilers}
233233
[ 1000 [ driver eval2 ] times ] time => 3ms run / 0 ms GC time
234234
\end{verbatim}
235235

236-
There is obviously room for improvement in the 'match' routines! I can
236+
There is obviously room for improvement in the `match' routines! I can
237237
say that because I wrote them :)
238238

239239
A compiler follows the same structure as the interpreter but instead
@@ -242,13 +242,16 @@ \chapter{Compilers and Interpreters}\label{compilers}
242242
pattern matching based example. The generic word implementation is
243243
very similar and would follow the relevant interpreter implementation.
244244

245-
Factor provides a 'make' word that can be used for dynamically appending to a new sequence. From within a 'make' scope you can use ',' to append an element and '%' to splice in a sequence to the constructed sequence. 'make' can be used for constructing arrays, strings, quotations, etc. The type of the constructed sequence is identified by an exemplar sequence passed to 'make'. For example:
245+
Factor provides a `make' word that can be used for dynamically appending to a new sequence. From
246+
within a `make' scope you can use `,' to append an element and `\%' to splice in a sequence to the
247+
constructed sequence. `make' can be used for constructing arrays, strings, quotations, etc. The type
248+
of the constructed sequence is identified by an exemplar sequence passed to `make'. For example:
246249

247250
\begin{verbatim}
248251
[ 1 , 2 , { 3 4 } % { 5 } , ] { } make => { 1 2 3 4 { 5 } }
249252
\end{verbatim}
250253

251-
The top level 'compile' word will set up a 'make' scope for the AST
254+
The top level `compile' word will set up a `make' scope for the AST
252255
compile routines to append to. Here's the compiler to Factor:
253256

254257
\begin{verbatim}
@@ -271,24 +274,24 @@ \chapter{Compilers and Interpreters}\label{compilers}
271274
\end{verbatim}
272275

273276
As you can see it is very similar to the interpreter. Instead of
274-
returning the result of the AST evaluation '(compile1)' appends the
277+
returning the result of the AST evaluation `(compile1)' appends the
275278
equivalent Factor code to the constructed quotation created in the
276-
'compile1' word.
279+
`compile1' word.
277280

278-
The implementation for handling 'lit' just appends the numeric value
279-
directly. For 'inc' it calls '(compile1)' on the term to be
281+
The implementation for handling `lit' just appends the numeric value
282+
directly. For `inc' it calls `(compile1)' on the term to be
280283
incremented so that gets appended to the quotation. It then appends
281-
the Factor '1+' word which will be used to increment it. The '\' is an
284+
the Factor `1+' word which will be used to increment it. The `\' is an
282285
escape mechanism to tell Factor to store the word itself rather than
283286
call it.
284287

285-
The main complication is in the implementation of 'iff'. This word
286-
must delay the computation of the two terms of the 'iff' statement. To
287-
to this it creates Factor quotations with 'make' and then recursively
288-
calls '(compile1)' for the terms. The results of the compilation for
288+
The main complication is in the implementation of `iff'. This word
289+
must delay the computation of the two terms of the `iff' statement. To
290+
to this it creates Factor quotations with `make' and then recursively
291+
calls `(compile1)' for the terms. The results of the compilation for
289292
this recursive call will be stored in the most recently created
290-
quotation rather than the one in the top level 'compile1' word. That
291-
is, nested 'make' calls are dynamically scoped.
293+
quotation rather than the one in the top level `compile1' word. That
294+
is, nested `make' calls are dynamically scoped.
292295

293296
An example of usage of the compiler:
294297

@@ -297,7 +300,7 @@ \chapter{Compilers and Interpreters}\label{compilers}
297300
[ 5 1 + ] call => 6
298301
\end{verbatim}
299302

300-
The 'driver' AST shown previously compiles to Factor correctly:
303+
The `driver' AST shown previously compiles to Factor correctly:
301304

302305
\begin{verbatim}
303306
driver compile1 => [
@@ -319,7 +322,7 @@ \chapter{Compilers and Interpreters}\label{compilers}
319322

320323
The final example is a compiler to Javascript. Again it follows the
321324
same basic outline of the interpreter. Instead of generating a Factor
322-
quotation it uses 'make' to generate a string:
325+
quotation it uses `make' to generate a string:
323326

324327
\begin{verbatim}
325328
: (compile2) ( a -- )
@@ -346,17 +349,17 @@ \chapter{Compilers and Interpreters}\label{compilers}
346349
[ "(" % (compile2) ")" % ] "" make ;
347350
\end{verbatim}
348351

349-
The main complication with this compiler was handling 'if'. The
350-
Javascript 'if' has no result so cannot be assigned immediately. So I
351-
wrap the 'if' in a function which is called immediately. The two terms
352-
of the 'if' use 'return' to return the result from the function. A
352+
The main complication with this compiler was handling `if'. The
353+
Javascript `if' has no result so cannot be assigned immediately. So I
354+
wrap the `if' in a function which is called immediately. The two terms
355+
of the `if' use `return' to return the result from the function. A
353356
simple example:
354357

355358
\begin{verbatim}
356359
5 <lit> <inc> compile2 => "(5+1)"
357360
\end{verbatim}
358361

359-
And 'driver' also compiles successfully:
362+
And `driver' also compiles successfully:
360363

361364
\begin{verbatim}
362365
driver compile2 =>

0 commit comments

Comments
 (0)