You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running the 'eval1' word on this produces the answer, { 7 8 }:
182
+
Running the `eval1' word on this produces the answer, { 7 8 }:
183
183
184
184
\begin{verbatim}
185
185
driver eval1 => { 7 8 }
186
186
\end{verbatim}
187
187
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
189
189
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
191
191
extend the interpreter without having to modify existing code. Here's
192
192
a generic word approach to the interpreter:
193
193
@@ -203,24 +203,24 @@ \chapter{Compilers and Interpreters}\label{compilers}
203
203
M: snd eval2 ( a -- a ) snd-t eval2 second ;
204
204
\end{verbatim}
205
205
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
207
207
similar to how generic functions and methods work in CLOS and
208
208
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:'
210
210
is the type of that object that that method is for. The second is the
211
211
name of the generic word the method will be added too. The rest of the
212
212
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':
215
215
216
216
\begin{verbatim}
217
217
driver eval2 => { 7 8 }
218
218
\end{verbatim}
219
219
220
220
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
224
224
be compiled to native code. This can be seen by trying to compile the
225
225
examples and running a timed test:
226
226
@@ -233,7 +233,7 @@ \chapter{Compilers and Interpreters}\label{compilers}
233
233
[ 1000 [ driver eval2 ] times ] time => 3ms run / 0 ms GC time
234
234
\end{verbatim}
235
235
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
237
237
say that because I wrote them :)
238
238
239
239
A compiler follows the same structure as the interpreter but instead
@@ -242,13 +242,16 @@ \chapter{Compilers and Interpreters}\label{compilers}
242
242
pattern matching based example. The generic word implementation is
243
243
very similar and would follow the relevant interpreter implementation.
244
244
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:
0 commit comments