70 | 70 |
4 $ dup
|
71 | 71 |
===> 4 4 $
|
72 | 72 |
|
|
73 |
The numbers that the arithmetic operations work on, are unbounded integers.
|
|
74 |
The following example is of course no proof of that, but it's illustrative:
|
|
75 |
|
|
76 |
$ 1000000000000000 1000000000000001 + dup *
|
|
77 |
===> 4000000000000004000000000000001 $
|
|
78 |
|
|
79 |
This fact will become important later on.
|
|
80 |
|
73 | 81 |
Defining functions
|
74 | 82 |
------------------
|
75 | 83 |
|
|
115 | 123 |
|
116 | 124 |
Note there is another restriction: exactly one `$` symbol must occur to
|
117 | 125 |
the left of the `->`, and exactly one `$` symbol must occur to the right
|
118 | |
of the `->` as well. Often the `$` will simply be in the leftmost
|
119 | |
position in both of these occurrences, as in the example above, but this
|
120 | |
is not required.
|
121 | |
|
122 | |
TODO failing exmple
|
|
126 |
of the `->` as well. If this is not the case, the implementation may
|
|
127 |
flag up some kind of warning, but at any rate, it will erase the special
|
|
128 |
form, but it not introduce any new rules.
|
|
129 |
|
|
130 |
$
|
|
131 |
: $ ten -> 10 ;
|
|
132 |
ten
|
|
133 |
===> $ ten
|
|
134 |
|
|
135 |
$
|
|
136 |
: ten -> $ 10 ;
|
|
137 |
ten
|
|
138 |
===> $ ten
|
|
139 |
|
|
140 |
$
|
|
141 |
: ten -> 10 ;
|
|
142 |
ten
|
|
143 |
===> $ ten
|
|
144 |
|
|
145 |
Often the `$` will appear in the leftmost position in both the pattern
|
|
146 |
and the replacement, as in the above examples, but this is not required.
|
123 | 147 |
|
124 | 148 |
Recursion
|
125 | 149 |
---------
|
|
182 | 206 |
a strict stack discipline you have a push-down automaton, not a Turing
|
183 | 207 |
machine.
|
184 | 208 |
|
185 | |
But that assumes this is a traditional stack-based language,
|
|
209 |
We do have unbounded integers, so if we had division, or `swap`, we might
|
|
210 |
be able to make a 1-counter or 2-counter [Minsky machine][]. But we don't
|
|
211 |
have those operations.
|
|
212 |
|
|
213 |
And anyway, that all assumes this is a traditional stack-based language,
|
186 | 214 |
which it's not! It's a string-rewriting language, and it naturally has
|
187 | 215 |
access to the deep parts of the stack, because it looks for patterns in them.
|
188 | 216 |
|
|
201 | 229 |
stack discipline does, i.e. it can only compute what a push-down automaton
|
202 | 230 |
can compute.
|
203 | 231 |
|
204 | |
However,
|
205 | |
|
206 | |
* as I said, I haven't proved this, and it relies on the fact that
|
207 | |
user-defined rules can't have patterns with variables and that we
|
208 | |
can't simulate variables over a finite set of possible elements
|
209 | |
they can match by introducing one rule for every element of that
|
210 | |
finite set.
|
211 | |
* we haven't restricted the redex to containing exactly one `$` and I
|
212 | |
haven't thought through what the implications of having more than one
|
213 | |
`$` in it are anyway.
|
|
232 |
There is a caveat here: it relies on the fact that user-defined rules
|
|
233 |
can't have patterns with variables. Thue's strings are defined over a
|
|
234 |
finite alphabet, so you can simulate a pattern having variables by
|
|
235 |
exhaustively listing all the possible symbols that could be matched,
|
|
236 |
and having one rule for each combination. e.g. you can say
|
|
237 |
`1+1=2`, `1+2=3`, `1+3=4`, etc., etc. But you *can't* do that in Wanda,
|
|
238 |
because Wanda has unbounded integers.
|
|
239 |
|
|
240 |
Also, we haven't restricted the redex to containing exactly one `$` and I
|
|
241 |
haven't fully thought through the implications of having more than one
|
|
242 |
`$` in it. And I haven't got a proof for any of this anyway.
|
214 | 243 |
|
215 | 244 |
So the approach we'll take in the remainder of this document is to
|
216 | 245 |
add some features and show that they make the language Turing-complete,
|
217 | 246 |
even if Core Wanda already is.
|
218 | 247 |
|
219 | |
[2-register machine]: https://esolangs.org/wiki/Minsky_machine
|
|
248 |
(And after that I might just go wild and add variables in user-defined
|
|
249 |
rules anyway.)
|
|
250 |
|
|
251 |
[Minsky machine]: https://esolangs.org/wiki/Minsky_machine
|
220 | 252 |
[Thue]: https://esolangs.org/wiki/Thue
|
221 | 253 |
|
222 | 254 |
Concrete Shoes and Fishing Lines
|