Dwelv

From Esolang
Jump to navigation Jump to search

Dwelv is an esolang created by CreeperBomb in 2023 with a string-rewriting paradigm with a single editable string. It is Turing complete as it can simulate a Minsky machine. It was made whlie trying to describe how something changed in a scrapped language.

Specification

The first line contains how the string will start as. Each line after that will be run begins with a "state name", then a colon and space, and then the state's code ("sequence (of instructions)"/"code sequence"/etc.). If a line is not structured like this or the code is invalid, the line will be ignored and treated like a comment.The first line is run first, and states will loop unless interrupted. State names may not contain quotes, apostrophes, whitespace other than regular space, trailing or beggining space, parenthesis, square brackets, curly brackets, pipes, backticks, commas, semicolons, or colons.

Each neighboring instruction in a state is seperated by either a comma or semicolon (plus a space). If seperated by a comma and the first is run and "fails" (has no impact), then the second instruction is run but is otherwise skipped. For example, in A, B, C C would only be run if both A & B fail. If seperated by a semicolon, then both will always run in sequence. In A, B; C, C would always run but B may not. You can also use parenthesis to group instructions together, so in A, (B; C) C would only run when B ran, unlike the previous example.

There are two instruction types: replacement and changing the state. Replacement is structured as "[Initial string]" -> "[Final string]". The quotes can also be apostrophes with no effect. Any instance of the initial string will replaced with the final string, with leftward preference (so "11" -> "00" on 111 results in 001). It has some special characters that come with it, which can be escaped using `. They are:

Character(s) What they do
" & ' Starts/ends string in a replacement
` Escapes special characters
[] The number inside represents that many unspecified characters
{} Character(s) from a set of comma-and-space-seperated characters. In the final string slot, this acts like a randomizer
| Used to combine [] and {}, [] and (), or {} and (), such as in [4|c, a, ns}
() Named unspecified characters. For example, "(A)A" -> "A(A)" would make A move left one character
`n Stand-in for a newline
# Stand-in for an edge of the string (start or end)
? Becomes user input

Changing the state is done by writing the state name. If the state changed to does not exist, the program will halt.

Turing completeness

Dwelv is Turing complete, even with the limitation of only having two characters that can be used in the string. This is provable by converting any Minsky machine program to a Dwelv program in the following manner and starting with "LR".

Minsky Dwelv
Left incrementation "LR" -> "LLR"
Right incrementation "LR" -> "LRR"
Left decrementation "LLR" -> "LR", [failstate] where [failstate] is the failstate
Right decrementation "LRR" -> "LR", [failstate] where [failstate] is the failstate

The rest, namely state names and multiple operations per state, is trivial.

Example programs

Rickroll the user if they can't do 1+1

1+1=?
Not sorry: "2"-> "2", "1+1=[1]" -> "Never gonna give you up, never gonna let you down"; Halt

Hello world/quine

Hello world

Truth machine

?
Truth: "0" -> "0", ("1" -> "11", "[1]" -> "?"; Truth); Halt

A bunch of programs to test implementations (also should probably test truth and Minsky machines). They should become Test: "Not" -> "Code", Not, and banana, respectively

Test: "Not" -> "Code"
Not
Test: "Not" -> "Code
bnn
: ""  -> "a"; "#ab" -> "b"
;Should become "banana"