esolang

Strvar

Variables that hold strings, and a string that names a variable turns into its value.

PythonshellDebugwindow, 2020 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 6 known programs · Test method

Run it

Expected: Hello, World!

The idea

PythonshellDebugwindow made Strvar in 2020. There are only two kinds of line. One stores a string in a variable, the other prints a string. Every time a string is used, the variable names written in it are replaced by their values, the leftmost first, until none of them is left. So a string prints the value of a variable just by spelling its name, and a replacement that brings back the same name never finishes.

The machine

LineDoes
name = "text";Store the text, with names in it replaced, in the variable
"text";Print the text, with names in it replaced, and a line feed
# ...A comment to the end of the line

Strings know the escapes \r \n \" \t and \xhh. Spaces outside strings are dropped, so my var and myvar are one name. A name is replaced by the value it has at that moment, so a variable keeps a copy and does not follow later changes.

Example

A counter.
Expected: Hello, World!

A counter. two is stored as 1 2 and three as 1 2 3, so printing three gives the count.

Expected: 1 2 3

The two test cases. In the first, a holds b, and the b that comes out of a is not replaced again. In the second, a took the value x while b held it, and keeps it.

Expected: b
Expected: x

The specification does not say exactly which names count. In this implementation they are the names the string holds as written, and those are replaced again and again until none is left. That is the plainest reading that gives both test cases. With w = "world!" the program "h w" never prints, because each w that is replaced brings a new one, as the specification says.

Patterns it teaches

  • String rewriting: a program's whole work is replacing names in text until nothing is left to replace.

Further

String-rewriting paradigm

Write your own in Run Convert a program from Strvar

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: strvar.

Command line

shib run strvar -e '1 = "0";
"1";'
shib manual strvar

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/strvar.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org