Quassaunt

From Esolang
Jump to navigation Jump to search

Quassaunt is an esolang by User:BoundedBeans based around sets and reverse-polish notation.

Data

Everything in Quassaunt is either a set or a string. Variables can only be created as sets, but strings can be on the evaluation stack for the notation, and they can be manipulated there. Sets may contain either strings or sets.

Syntax

Every piece of syntax is a word. Words can have any character except for space, tab, linefeed, or carriage return. (Vertical tabs and form feeds can be contained within words, but they aren't really necessary for anything. However, they do obfuscate code, a high priority of this language.) Strings are always represented as words, so they may never contain whitespace literally.

Commands

%%Empty ( -- set) Push an empty set.
@@(text) ( -- str) Push a string with the text.
%%Store (str set -- ) Store the set into the variable with the name of the string. Any variables with names enclosed in square brackets are global, otherwise they are local.
%%Obtain (str -- set) Retrieve the set from the variable with the name of the string. The variable @@[Whitespace] contains the string " \t\n\r", and this is the only way to obtain whitespace characters in strings.
%%Concatenate (str str -- str) Concatenate the top string to the bottom string.
%%Makecontain (val set -- set) Add a value to a set. If it already contains it, store the set @@No_duplicates_are_allowed_in_a_set. %%Empty %%Makecontain in the variable @@Errormessage and push the empty set.
%%Makenotcontain (set val -- set) Make the set not contain the value. If it doesn't contain it, store the set @@The_set_does_not_contain_the_value_entered. %%Empty %%Makecontain in the variable @@Errormessage and push the empty set.
%%Concatenateall (str dummy set dummy -- str) Ignores some required useless values and gets the string with all the strings in the set concatenated with a separator in between. The order (or absence of one) that the strings are concatenated is implementation-dependant. Sets should not be included.
%%Evaluate (str -- ?) Evaluates the string on the top of the stack as Quassaunt code, with the stack shared. Words will be separated with "?" (without quotes) rather than whitespace.
%%Evaluatepermanently (str -- ) Like %%Evaluate, but never returns. You can use this to accomplish tail recursion and truly infinite looping. Also completely throws the existing call stack away, since it won't be needed anymore.
%%Ifpropersubset (str set str set -- ?) If the top set is a proper subset of the bottom set, evaluate the bottom string, otherwise, evaluate the top string.
%%Ifdisjoint (str set str set -- ?) If the top set is disjoint to the bottom set, evaluate the bottom string, otherwise, evaluate the top string.
%%Printtoconsole (str -- ) Prints a string to the console.
%%Inputchar ( -- str) Gets a character of input as a single-character string.
%%Delete (str -- ) Deletes the variable with the name of the string.
%%Head (str -- str) Returns the first character of the string.
%%Tail (str -- str) Returns everything but the first character of the string.

Extensions

%%Multithread (str str -- ) Evaluates the two strings in parallel, sharing global variables but having separate local variables.

Other conditions besides %%Ifpropersubset

They can all be emulated.

A NOT gate can be made by using the else block.

An OR gate can be made by having the false blocks be empty and having two conditions with the same true block.


An AND gate can be made by nesting conditions.

Checking for a proper superset can be emulated by switching the sets around.

Checking for disjoint or equal can be emulated with NOT proper subset AND NOT proper superset.

Checking for equal can be emulated with (disjoint OR equal) AND NOT disjoint.

Checking for a superset can be emulated with proper superset OR equal.

Checking for a subset can be emulated with proper subset OR equal.

Checking if a set contains an element can be implemented with a non-proper subset or non-proper superset where one of the sets contains only one element.

Checking if strings are equal can be implemented with a check for equality where both sets contain only one element.

These may be easier to understand if the false block is empty.

You can also make recursion (for looping) by running storing a evaluatable string in a global variable and running it within itself (possibly conditionally).

Stack manipulation

You may notice there is no stack manipulation. This can be emulated.

You can emulate a pop by storing into a dummy variable.

You can emulate a dup by storing into a dummy variable and retrieving it twice.

You can emulate a swap by storing into two dummy variables and re-pushing them in the same order they were popped (not reversed).

Examples

Hello_world!

@@Hello_world! %%Printtoconsole

Truth-machine

@@[Input] %%Inputchar %%Empty %%Makecontain %%Store
@@[0]     @@0         %%Empty %%Makecontain %%Store
@@[1Out]
  @@@@1?%%Printtoconsole?@@?@@?@@[1Out]?%%Obtain?@@?
  @@%%Concatenateall?%%Evaluate
  %%Concatenate
  %%Empty
  %%Makecontain
%%Store

@@@@0?%%Printtoconsole
@@[Input] %%Obtain
@@@@?@@?@@[1Out]?%%Obtain?@@?%%Concatenateall?%%Evaluatepermanently
@@[0]     %%Obtain

@@@@0?%%Printtoconsole
@@[0]     %%Obtain
@@%%Ifpropersubset
@@[Input] %%Obtain