Daoyu
A bit tape is a tree. You never point at a bit; you halve your view of it and merge it back.
Kaynato, 2016 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Kaynato made Dàoyǔ (道语) in 2016, modeled on a couple of tenets of Daoist philosophy. Every tape of bits has a length that is a power of two, and a reader sees it as a tree. A reader does not walk the tape bit by bit. It halves its selection, takes the other half, or merges back up to the parent node.
Read the story
The sixteen operations are the sixteen hex digits, so every stream of bytes is a program. The program is a bit tape too, and data readers can climb into it, read it and rewrite it. Tapes nest. The program tape has a child tape for data, a reader can climb from a child into its parent, and # runs a selection as a new program.
The machine
| Symbol | Hex | Name | Does |
|---|---|---|---|
. | 0 | IDLES | Nothing |
! | 1 | SWAPS | Swap the two halves of the selection |
/ | 2 | LATER | Go from a left half to the right half, else merge |
) ] | 3 | MERGE | Select the parent node, or the parent tape's first bit |
% | 4 | SIFTS | Move zero hexes to the end of the tape |
# | 5 | EXECS | Run the selection as a program on the child tape |
> | 6 | DELEV | Lower the level |
= | 7 | EQUAL | Skip the next hex unless the first and last bits are equal |
( | 8 | HALVE | Select the left half, or go down to the child tape |
< | 9 | UPLEV | Raise the level and restart the program |
: | A | READS | Print the selection |
S | B | DEALC | Halve the tape, or destroy a tape of one bit |
[ | C | SPLIT | Set the left half to 1s and the right to 0s, then halve |
* | D | POLAR | Skip the next hex unless the first bit is greater than the last |
$ | E | DOALC | Double the tape with 0s, then merge |
; | F | INPUT | Read bytes into the selection |
Each executor has a level, and most operations work only at low levels. At level 1 $ does nothing and [ only halves, so a program can restart with < and skip its own setup. The specification's table of levels is an image; an operation does nothing above the levels the text gives it.
Example
$$$ doubles the one data bit three times into a byte of 0s.
$$$ doubles the one data bit three times into a byte of 0s. (( selects its first two bits and []! makes them
)/(moves to the first two bits of the second nibble,[]makes them 10, and))climbs back to the byte.
That is 0100 1000, which is 72.
The Hello World edits that one byte line by line, printing it with : after each.
The cat reads a byte, prints it and restarts with <. Back at level 1 the three $ do nothing, and > lowers the level again for the next byte. The end of the input ends the run.
The shorter Hello World climbs out of its data into the program itself and prints its own second line, whose symbols spell Hello world!, a line feed and three NUL bytes. Then S cuts that half off the program. The truth machine prints 0 and ends on 0, and prints 1 for ever on 1.
Patterns it teaches
- Self-modifying code: data readers can climb into the program and change it.
- Every text runs: sixteen operations for sixteen hex digits.
- Code as data: a program prints text by reading its own symbols as bytes.
Further
See also
Self-modifying
Cell-based
Write your own in Run Convert a program from Daoyu
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: daoyu.
Command line
shib run daoyu -e '))))))))/:((((((S...............
%(>#>[>[>;/.==>;=/>[>%/!.:......'shib manual daoyuSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/daoyu.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org