Initial import of description of Kelxquoia.
catseye
9 years ago
0 | Kelxquoia | |
1 | ========= | |
2 | ||
3 | Kelxquoia is an esoteric programming language designed by Chris Pressey on | |
4 | December 23, 2010. It is a self-modifying, in fact self-*destroying*, | |
5 | language which combines grid-rewriting with remotely fungeoid playfield | |
6 | traversal. | |
7 | ||
8 | Program State | |
9 | ------------- | |
10 | ||
11 | There is an instruction pointer (IP) with a location and a direction in an | |
12 | unbounded, two-dimensional Cartesian grid of symbols. As the IP passes over | |
13 | symbols, it executes them and erases them from the playfield (overwrites | |
14 | them with blanks). The program ends when the IP travels off into space, never | |
15 | to return. | |
16 | ||
17 | There is a stack. The stack may contain objects of two types, grids and rows. | |
18 | Instructions expect certain types of objects to be present on the stack; if | |
19 | the types are incorrect, or insufficient elements are on the stack, the | |
20 | instruction has no effect. (That means that the state of the stack, too, is | |
21 | unchanged by the instruction.) | |
22 | ||
23 | Instructions | |
24 | ------------ | |
25 | ||
26 | If the IP passes over any symbol _x_, and there is a `'` symbol to the right | |
27 | of the IP's line of travel, a row is popped from the stack, the symbol _x_ is | |
28 | appended (to the rightmost position) of that row, and the new row is pushed | |
29 | back onto the stack. The symbol _x_ is erased, but the `'` is not. | |
30 | ||
31 | The instruction `-` pushes an empty row onto the stack. | |
32 | ||
33 | The instruction `+` pushes an empty grid onto the stack. | |
34 | ||
35 | The instruction `*` pops a row, pops a grid, appends the row to the bottom of | |
36 | the grid, then pushes the new grid. Note that the left-hand edges of every | |
37 | row in a grid line up, but their right-hand edges need not do that. When | |
38 | considered as a grid, all unused squares in the grid are considered to contain | |
39 | blanks. | |
40 | ||
41 | The instruction `?` pops a row from the stack, appends a wildcard to it, and | |
42 | pushes the new row back onto the stack. | |
43 | ||
44 | The instruction `/` pops a grid called the _replacement_, then pops a grid | |
45 | called the _pattern_, then replaces all non-overlapping occurrences of the | |
46 | pattern in the playfield with the replacement. All overlapping occurrences | |
47 | are untouched, to avoid ambiguity. A few things to note: | |
48 | ||
49 | * The replacement must not be any larger than the pattern. If it is, the | |
50 | two grids remain popped but the instruction otherwise has no effect. | |
51 | * If the replacement is smaller than the pattern, it is padded with blanks | |
52 | (to the bottom and to the right.) | |
53 | * There can be at most one wildcard in the pattern. If there are no | |
54 | wildcards in the pattern, there should be none in the replacement. If | |
55 | either of these conditions does not hold, the two grids remain popped | |
56 | but the instruction otherwise has no effect. | |
57 | * Any symbol in the playfield may match the wildcard in the pattern. | |
58 | Where-ever there is a wildcard in the replacement, the symbol that matched | |
59 | the wildcard in the pattern is substituted instead. | |
60 | * If the executed `/` instruction itself is replaced by something during | |
61 | this process, whatever it was replaced with will not be erased. | |
62 | * If the pattern consists only of blanks, or only wildcards, the | |
63 | implementation may choose to halt the program rather than filling the | |
64 | entire playfield with replacement. | |
65 | ||
66 | The instructions `>`, `<`, `^`, and `v` cause the IP to begin travelling east, | |
67 | west, north, and south, respectively. | |
68 | ||
69 | The instruction `!` clears the stack. | |
70 | ||
71 | Executing any other symbol as an instruction has no effect. | |
72 | ||
73 | The symbol `$` indicates the initial position of the IP. The initial | |
74 | direction of the IP is always east. If there are multiple `$` symbols in the | |
75 | source code, it is an error and the program is not executed. | |
76 | ||
77 | Computational Class | |
78 | ------------------- | |
79 | ||
80 | The author believes Kelxquoia to be Turing-complete because: | |
81 | ||
82 | * Repeated use of the `/` instruction can be used to implement | |
83 | non-overlapping grid-rewriting, which can simulate an arbitrary Turing | |
84 | machine; see below. | |
85 | * Assuming all instructions that have been erased after execution can be | |
86 | restored, the IP can travel in a loop, to indefinitely apply the `/` | |
87 | rewrites. | |
88 | * Instructions that have been erased after execution can be restored by | |
89 | further rewrites of a certain, fixed form. | |
90 | * To effect a conditional halt, a critical direction-changing instruction | |
91 | can be selectively not restored to the playfield. | |
92 | ||
93 | ### Simulating a Turing Machine with non-Overlapping Grid-Rewriting ### | |
94 | ||
95 | In this section we show how a Turing machine can be simulated with | |
96 | grid-rewriting where we can match only non-overlapping instances of a pattern. | |
97 | (The addition of wildcards does not add any computational power, but does add | |
98 | some expressivity, as it can reduce the number of rewrites that need to be | |
99 | made.) The tape symbols of our machine will be the digits `0`-`9`, and the | |
100 | states of the finite control will be labeled with the lowercase letters | |
101 | `a`-`z`. In addition we will use the `.` symbol to depict whitespace, for | |
102 | clarity. | |
103 | ||
104 | We can depict each tape cell with the following 2x2 grid of symbols: | |
105 | ||
106 | 0T | |
107 | T+ | |
108 | ||
109 | We arrange the tape cells horizontally in the playfield, and we make sure | |
110 | there is only one such tape: | |
111 | ||
112 | 0T0T1T2T3T0T0T | |
113 | T+T+T+T+T+T+T+ | |
114 | ||
115 | We have rewriting rules that extend the tape in either direction, as needed: | |
116 | ||
117 | ?T.. -> ?T0T | |
118 | T+.. T+T+ | |
119 | ||
120 | ..?T -> 0T?T | |
121 | ..T+ T+T+ | |
122 | ||
123 | We situate the tape head directly below the cell of the tape we wish to | |
124 | affect, and again we make sure there is only one such head. The tape head | |
125 | looks like the following 2x2 grid: | |
126 | ||
127 | aH | |
128 | HN | |
129 | ||
130 | The upper-left corner contains the finite control label, and the lower-right | |
131 | corner contains a "movement indicator". When the head is ready to move, the | |
132 | movement indicator is changed, and we have the following two rewrite rules | |
133 | implement the move: | |
134 | ||
135 | ?H.. -> ..?H | |
136 | HR.. ..HN | |
137 | ||
138 | ..?H -> ?H.. | |
139 | ..HL HN.. | |
140 | ||
141 | Now, for each transition rule in the Turing machine, we can compose a | |
142 | grid-rewriting rule which implements it. For example, "In state `f`, if | |
143 | there is a `5` on the tape, write a `7` and move left" corresponds to the | |
144 | rule: | |
145 | ||
146 | 5T -> 7T | |
147 | T+ T+ | |
148 | fH fH | |
149 | HN HL | |
150 | ||
151 | From this description it should be fairly evident that this both simulates a | |
152 | Turing machine (not quite arbitrary, but certainly with sufficient symbols | |
153 | and states to be universal) and that the non-overlapping condition poses no | |
154 | obstacle (if the tape and head are arranged as described, these patterns will | |
155 | never match overlapping instances of the playfield). | |
156 | ||
157 | Examples | |
158 | -------- | |
159 | ||
160 | The following example replaces the words `WOW` and `POP`, at the bottom of | |
161 | the program, with `BOB` and `MOM`: | |
162 | ||
163 | $+-W*-P*+-B*-M*/ | |
164 | ' ' ' ' | |
165 | WOW | |
166 | POP | |
167 | ||
168 | The state of the playfield at the end of the program would be: | |
169 | ||
170 | $ | |
171 | ' ' ' ' | |
172 | BOB | |
173 | MOM | |
174 | ||
175 | The following example rewrites some stuff then restores the instructions that | |
176 | did the rewriting: | |
177 | ||
178 | +-0 0*+-1*/+-?*-R*- *+-?*-R*-?*/ | |
179 | RRRRRRRRRRRRRRRRRRR RRRRRRRRRRRR | |
180 | $+-0 0*+-1*/+-?*-R*- *+-?*-R*-?*/ | |
181 | ' ' ' ' ' ' | |
182 | ||
183 | 00 00 00 00 | |
184 | ||
185 | The following example extends the previous example to an infinite loop: | |
186 | ||
187 | >+-0 0*+-1*/+-?*-R*- *+-?*-R*-?*/v | |
188 | RRRRRRRRRRRRRRRRRRRR RRRRRRRRRRRRR | |
189 | $>+-0 0*+-1*/+-?*-R*- *+-?*-R*-?*/v | |
190 | ' ' ' ' ' ' | |
191 | ' ' ' | |
192 | ^ /*?-*P-*?-+*?-*P-* -+ < | |
193 | P PPPPPPPPPPPPPPPPPP PP P | |
194 | ^ /*?-*P-*?-+*?-*P-* -+ < | |
195 | ||
196 | 00 00 00 00 | |
197 | ||
198 | Acknowledgements | |
199 | ---------------- | |
200 | ||
201 | The contents of this document were taken from the Kelxquoia article on the | |
202 | esolangs.org wiki, which is in the public domain. |