We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Assert

From Esolang
Jump to navigation Jump to search

Assert is an esolang invented by User:None1. As the name suggest, conditionals in this esolang are done by assertion.

Multithreading

This esolang supports multithreading. How it supports that is mentioned in the Operators section.

Syntax

Variables

This esolang uses unbounded signed variables. There are two kinds of variables: normal variables and atomic variables. Assigning to a non-existent variable automatically creates it and reading a non-existent variable returns 0.

Normal variables

The rule for naming normal variables is the same as that of most practical programming languages: Only alphanumeric characters (and most non-ASCII Unicode characters) plus underscore are allowed. Normal variable names mustn't start with a digit or coincide with a keyword.

Normal variables are local in threads, which means that a thread cannot access normal variables in other threads.

Atomic variables

Atomic variables are global variables, and as the name suggests, only one thread can modify it at a time. The naming rule for atomic variables is the same as that of normal variables, except that atomic variables start with an @ character.

Commands

There are four kinds of instructions: Assignment instructions, assertions, printing instructions and infinite loops. Commands execept the infinite loop command are separated by semicolons.

Assignment instructions

variable=expression

Set the value of variable to expression.

Assertions

assert expression1 [comparison expression2]

comparison can be ==,!=,>,<,>=,<. If the condition isn't satisfied, the thread is terminated. If comparison and expression2 aren't given, the assertion terminates the thread expression1 is zero.

Printing instructions

print "string"

prints the string. escape sequences are allowed.

print expression

prints the value of expression.

Infinite loops

{
  CODE
}

Executes CODE forever.

Operators & Precedence

  • brackets
  • unary +,unary -
  • *,/(floor division),%
  • binary +,binary -
  • bit operations, precedence the same as C++.
  • :(threading operator)

Threading operator

The threading operator is a special operator in assert. It is used like this:

expression1:expression2

This operator spawns another thread. In the current thread, this evaluates to expression1 (and expression2 is never evaluated). In the other thread, this would evaluates as expression2 (and expression1 is never evaluated).

Of course, you can spawn two threads using the threading operators using the following syntax:

a:b:c

This is because it is interpreted as:

(a:b):c

Which evaluates to a:b (which then spawns another thread) in current thread, and c in the new thread.

Comments

Use # for comments:

code # comment
more code

Examples

Truth Machine

input=input number here;
print input;
assert input;
{print input;}

Replace input number here with the input number.

Calculate the sum of integers within 1~100

four=1:2:3:4;
eight=four:four+4;
sixteen=eight:eight+8;
thirty_two=sixteen:sixteen+16;
sixty_four=thirty_two:thirty_two+32;
hundred=four:(eight+4):(thirty_two+12):(sixty_four+36); # hundred stores a number within 1~100 in each thread
@sum=@sum+hundred; # Add up all the numbers
assert hundred==1; # Kill all the other threads so that the result is only printed once
print @sum;

Undefined behavior

id=1:2;
print "Hey I'm thread ";
print id;
print "!"

This is undefined behavior because multiple threads are printing at the same time. It might print:

Hey I'm thread 1!
Hey I'm thread 2!

Or:

Hey I'm thread 2!
Hey I'm thread 1!

Or even weirder outputs.

Fork bomb

{a=1:2;}

Computational class

Turing-complete, because it can simulate ChooseMatrix.

We first branch using threads:

d=0:1;

Then we can use:

a+(b-a)*d

for number a in the 0 branch and number b in the 1 branch.

Therefore, we can easily multiply one matrix in the 0 branch and the other in the 1 branch, and wrap it with an infinite loop.

This doesn't even use conditionals, but it's still TC.