sdac2
Two lists, six operators, and a loop that always runs its body once more.
Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
sdac2 has a list of numbers and a second list that holds a single number. / switches between them, and each operator does something else in each list. The specification explains the operators in a few words and carries a short Python interpreter, so this implementation follows that interpreter, quirks included. Whether the language is Turing complete, the specification says, is not known.
Read the story
The quirk that matters most is the loop. A pair of * repeats the code between them while the current number is not 0. Then the interpreter walks on into that same code, so the body runs once more after the loop ends, and once even when the loop never starts. Loops cannot nest.
The machine
| Operator | In list 1 | In list 2 |
|---|---|---|
+ | Add 1 to the current number | Add list 1's current number to this one and remove it from list 1 |
- | Take 1 from it | Put this number at the front of list 1 |
. | Print it as a character | Print this one as a character |
, | Read a line and keep its first character | Set this one to 0 |
/ | Switch to list 2 | Switch to list 1 |
* ... * | Repeat while the current number is not 0 | The same |
List 1 starts as one 0. After list 2's + its pointer is at the front, and after list 2's - it is on the second item, the one that was at the front. Python's print puts a line feed after every character. A program with an odd number of * only prints an error line.
Example
The first is the Fibonacci number.
The first is the Fibonacci number. The five +/ pairs leave 1 in list 1 and 2 in list 2. Each -+ then puts list 2's number at the front of list 1 and adds in the number behind it, so list 2 goes 3, 5, 8, 13, 21, 34, 55 and 89, and . prints 89 as Y.
The repeat program doubles its way to 32, makes 65 in list 2 from 33 and 32, reads a character and counts its code down to 0, printing A on each step. With the input !, code 33, the extra pass of the body makes that 34 lines of A.
Patterns it teaches
- Stack machines: list 2 pushes onto the front of list 1, and its
+pops from there. - Turing tarpit: six operators on two lists.
Further
See also
Stack-based
Write your own in Run Convert a program from sdac2
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: sdac2.
Command line
shib run sdac2 -e '+*.'shib manual sdac2Source
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/sdac2.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org