-string

From Esolang
Jump to navigation Jump to search

-string is a language designed by User:Runius in July 2025 Inspired by This=That

-string is a language which parses almost all text in the program before running it, making it very strong but also very difficult to write in. The full algorithm for parsing text is described in its own section below.

Language overview

-string has a total of 4 types of statements available, being assignment, commands, labels, and comments in no particular order. They are described below.

Assignment

An assignment statement is determined by the presence of an equals sign surrounded by whitespace ( = ). The two halves of the equation are parsed separately, then the value on the right is stored in the variable of the name of the value on the left.


For example, this statement stores the value b into variable a

-a = -b


There are 2 special variables in assignment, which operate the I/O systems of the language.

The in variable, when parsed on the right side of the expression, will stop to wait for user input, accepting a full string.

The out variable, when assigned to, will print out the value it is given to the console.

Commands

A command statement uses a special character followed by whitespace at the start of a line. The special character determines the effect of the command, as listed below. All commands operate on a single value determined from a parsed expression.

command function
! Jumps to the label determined by the value, if label does not exist does nothing.
+ Increments the variable determined by the value, if it is a number.
- Decrements the variable determined by the value, if it is a number.


This snippet will jump the program to the label next

! -next


This snippet will increment the variable counter

+ -counter


This snippet will decrement the variable counter

- -counter

Labels

A label is signified by a line starting with a colon followed by a whitespace character. Unlike most statements in -string, a label is not parsed, and its name is simply used in the jump command as a marker for program lines.


This line defines the label next

: next

Comments

Any line which does not meet the criteria to be interpreted as any other statement is interpreted as a comment and is ignored.

// This is a comment!
# This too!
And this!

String parsing

When strings are parsed, each whitespace separated token is individually evaluated, before being concatenated into the final result string.

By default, a token is treated as a variable name, and will fetch the value of the variable to add to the string. If the variable does not exist, an empty string will be supplied instead A string literal is preceded by the - character, for example -text evaluates to "text"

The unique empty literal - will produce a whitespace character when parsed, and due to the whitespace separation requirement of the language, this is usually the only way to insert whitespace into a string.


The most important part of -string syntax is the square brackets []. Any tokens enclosed in square brackets will be evaluated once before the evaluation of the rest of the string, essentially making them be evaluated twice.

[--Layered] -Parsing

For an example of this behavior, the above equation will first evaluate the string literal in the square brackets, --Layered into -Layered, which is inserted in place into the equation to form -Layered -Parsing, finally becoming LayeredParsing.

This functionality can essentially be used to replicate pointers such as in C, and allows for the creation of data structures such as linked lists.

Computational class

Assuming that a jump to a label that doesn't exist doesn't result in an error or undefined behavior, -string should be Turing complete.

If an attempted jump to an invalid label does nothing then counter machines can be trivially implemented in -string by using ! -label counter, which will get the value of counter, append it onto the string label and attempt to jump to it. We would then have a corresponding : label0 label, which would be jumped to if the counter were zero. From the official examples, we see that this behavior is intended.

The behavior of [] likely also confers Turing completeness, in absence of a definite behavior for jumps to nonexistent labels.

Example programs

Hello, world!

-out = -Hello, - -world!

Cat program

-out = in

A+B Problem

Only works with positive integers.

-num1 = in
-num2 = in
: loop
+ -num1
- -num2
-exitCheck = num2 -Exit
! exitCheck
! -loop
: 0Exit
-out = num1

Truth-machine

! in
: loop
-out = -1
! -loop
: 0
-out = -0

FizzBuzz

Whitespace used for clarity.

-counter = -1
-fizzCount = -2
-buzzCount = -4

: loop

-next = 

-checkFizz = fizzCount -fizz
-checkBuzz = buzzCount -buzz
! checkFizz
! checkBuzz

-next = counter
! -continue

: 0fizz
-next = next -Fizz
-fizzCount = -3
! checkBuzz
! -continue

: 0buzz
-next = next -Buzz
-buzzCount = -5

: continue
-out = next

-exitCheck = counter -Exit

- -fizzCount
- -buzzCount
+ -counter

! exitCheck
! -loop
: 100Exit

Fun Video Game

-counter = -0

: loop

-counterCopy = counter
-input = in

: equalsLoop

-counterCheck = counterCopy -end
! countercheck

- -input
- -counterCopy
! -equalsLoop

: 0continue
-inputCheck = input -continue
! inputCheck
! -0end

: 0correct
+ -counter
! -loop

: 0end
-out = -FAILURE


External resources