git @ Cat's Eye Technologies Wanda / 8c6ec8e
A new rule must contain exactly one $ on both sides. Chris Pressey 6 years ago
2 changed file(s) with 54 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
7070 4 $ dup
7171 ===> 4 4 $
7272
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
7381 Defining functions
7482 ------------------
7583
115123
116124 Note there is another restriction: exactly one `$` symbol must occur to
117125 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.
123147
124148 Recursion
125149 ---------
182206 a strict stack discipline you have a push-down automaton, not a Turing
183207 machine.
184208
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,
186214 which it's not! It's a string-rewriting language, and it naturally has
187215 access to the deep parts of the stack, because it looks for patterns in them.
188216
201229 stack discipline does, i.e. it can only compute what a push-down automaton
202230 can compute.
203231
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.
214243
215244 So the approach we'll take in the remainder of this document is to
216245 add some features and show that they make the language Turing-complete,
217246 even if Core Wanda already is.
218247
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
220252 [Thue]: https://esolangs.org/wiki/Thue
221253
222254 Concrete Shoes and Fishing Lines
3939 pattern.append(redex[j])
4040 j += 1
4141
42 newrule = None
43 if len([s for s in pattern if s == "$"]) == 1 and len([s for s in replacement if s == "$"]) == 1:
44 newrule=dict(pattern=pattern, replacement=replacement)
45
4246 return dict(
4347 start=i,
4448 stop=j,
4549 pattern=["$", ":", "...", ";"],
4650 replacement=["$"],
47 newrule=dict(pattern=pattern, replacement=replacement),
51 newrule=newrule,
4852 )
4953
5054 if is_number(r0) and is_number(r1) and r2 == "$":