SoT

From Esolang
Jump to navigation Jump to search

SoT is short for "Stack of Tapes". (Note: I am still not finished! It takes a long time to do it!)

Comments and labels

Comments are indicated by /* and ending with */, or you can use // for a comment until end of line (but you can't put comments inside of strings, because it is interpreted as a string if you do it anyways). You must have a white-space before and after a comment, otherwise it isn't treated as a comment.

Labels defined in a code-block are : followed by label name followed by : again.

Kinds of values

  • Null: A null value is nothing and it is indicated in the program by a ^ sign.
  • Code-block: Function code-blocks are start with { and end with } and in between you put the commands.
  • Built-in-function: Built-in functions start with , or . or * or & or + and it is followed by one more character.
  • Number: A number of any size can be indicated by putting the number between two # signs. Negative, hex, octal, are also supported, as well as positive, and decimal numbers. You can use non-integers for decimal number but in other bases it has to be a positive integers. Hexadecimal start with 0x and octal start with 0.
  • Label-name: Label-names are also between two # signs but cannot start with a digit.
  • Variable-pointer: Variable names must be put between two ' signs to indicate a pointer to the variable with that name in the current scope.
  • String: A string is a text between " signs.
  • Quantum-pointer: It is a pointer to a qubit. There is no form for representing it.
  • Brainfuck: A brainfuck is a code between [ and ] and it can be any brainfuck codes in between. If used as a function and argument is a variable with non-empty stack, it will operate on that top tape of variable.
  • List: Put the list between ( and ) signs and each value (no separators are needed) will be a part of that list.
  • Regular-expression: A regular expression between slashes, but with # added before the beginning slash. It works similar to the preg functions in PHP but no pattern modifiers can be used outside of the slashes. The regular expression represents a set of strings. It is automatically anchored to the begin and end, so anchors doesn't do anything special.
  • Continuation: There is no form for representing a continuation. Qubits are not stored in continuations, but the quantum-pointers are.
  • Object: It is something that has any number of properties that are named by any value and can have any type of values as well. It has no representation. If a property name is exactly the same as a function that it is a argument for then it will execute the function that the property value is instead, unless the property value is null, in which case it uses the normal function instead. When object is used as a function, it uses the property named by a null as the function to call, and the argument to it is this object.
  • Boolean: Can be true or false. True is indicated by 1 and false by 0

Variables

A variable consists of a stack of tapes, the tapes are infinite in both directions and start all null, and the stack is also allowed to act as a queue in some cases. Variables must be declared before used, and variables defined locally to a subroutine override ones in a higher level.

Commands

  • Expression: It can be a expression represent a value and the result value is ignored.
  • Push to stack: Start with % and a expression, the result goes to the main stack.
  • Goto label: Start with ; and a expression and if it represents a label name that is in this code-block then it goto label. If the expression is a code-block instead, then it will execute that code-block (without arguments).
  • Exit from the function: Use ;; command to exit from function.
  • Declaration: To declare a variable you have to put = followed by variable name and then = again.
  • Maybe: ?M followed by any command acts like the MAYBE in backtracking INTERCAL. It puts to a state stack (except qubits).
  • Maybe not: ?m followed by any command is like MAYBE NOT (like ?M but is by default not executing).
  • Go back/ahead: ?B followed by a expression to do GO BACK if false, GO AHEAD if true, like it does in backtracking INTERCAL.
  • Quit: ?. to quit execution of entire program.

Operators

  • Apply operator: Apply one value (function) to the next value (argument), and returns its result value. The symbol is ` followed by first value, and then second value. If the function is a built-in function, you can abbreviate it `, to < and `. to > and `* to / and `+ to - and `& to \
  • Stack operator: If a % is used part of a expression then it pops from the main stack and uses that value. If there isn't any then it returns null. It does not need apply operator, it works automatically, before anything is applied in the current expression. If multiple percent signs then it pops from right to left.

Substitutions

Substitutions can be included in a code-block in place of a value by using a number with _ instead of # around it. Some functions can substitute them with proper values instead. It is an error to do a calculation with a substitution that hasn't been substituted yet.

Built-in functions

Remember that some functions might take multiple arguments by currying.

Quantum computer

  • ,1 x = Ignores x and return a new quantum-pointer to a new qubit with value 1.
  • ,0 x = Ignores x and return a new quantum-pointer to a new qubit with value 0.
  • ,% x = Hadamard transform on qubit pointed by x.
  • ,! x y = Controlled V on the x and y qubits.
  • ,O x = Observe the qubit x and returns false if 0 or or true if 1.
  • ,N x y = Controlled NOT on x as the control, and y as the target, return y.
  • +P x y = Phase shifter gate on qubit x with angle y. Returns x.

Variables

  • ,d x = Duplicate top of stack of variable x. Return x.
  • ,a x = Push blank tape to variable x. Return x.
  • ,z x = Discard top of stack of variable x. Return x.
  • ,Q x = Move bottom tape of stack of variable x to the top. Return x.
  • ,= x y = Set value of x at tape pointer to y. Return y.
  • .= x = Get value of variable x at tape pointer.
  • .< x = Move tape pointer of x one space backward. Return x.
  • .> x = Move tape pointer of x one space forward. Return x.
  • ,P x y = Set pointer of tape of x to position y (start position when variable is created is 0). Return y.
  • ,p x = Get pointer position of tape of x.
  • +Z x = Makes variable x so it cannot be changed. Return x.
  • +I x = Makes variable x so it can be changed. Return x.
  • ,_ x y = Get value at position y of tape of variable x.
  • ._ x y z = Set value at position y of tape of variable x to value z. Return z.
  • .u x y = Set values at all positions of tape of variable x to value y. Return x.
  • .y x = Renumber positions in tape of variable x so that where it points to is now position 0. Return number of what position 0 used to be numbered.
  • .Y x y = Add a position with value y in between every 2 positions of the tape of variable x. Position number of current position is retained.
  • ,Y x = Does the reverse function of .Y command.

Combinator function

  • .s x y z = S combinator function.
  • .k x y = K combinator function.
  • .i x = Identity function.
  • .v x = Returns .v function regardless of x.

Numbers

  • .+ x y = Adds numbers x and y.
  • .- x y = Subtracts numbers x and y.
  • .* x y = Multiplies numbers x and y.
  • ./ x y = Divides numbers x and y. (if dividing by zero, result is null)
  • .\ x y = Integer division.
  • .% x y = Modulo.
  • .& x y = Bitwise AND.
  • .| x y = Bitwise OR.
  • .^ x y = Bitwise XOR.
  • .! x = Bitwise NOT.
  • .$ x y = INTERCAL interleave operator.
  • .~ x y = INTERCAL select operator.
  • ,i x = Convert to integer.
  • ,A x = Absolute value of x.
  • ++ x = Sum of everything in the list x.

Continuations

  • .c x = Call x with current continuation.
  • .C x y = Push y to main stack of continuation x. Return x.
  • ,C x = Pop a value from main stack of continuation x.

Objects

  • .@ x = Create a new object with the null property set to x.
  • .o x y = Get value of property named y of object x.
  • .O x y z = Set value of property named y of object x to value z.

Input/Output

  • ., x = Ignores x, inputs one byte. Null if no more to read.
  • .. x = Output a byte x or a string x. Returns x.
  • .S x = Return a system calling object, ignores x.

Main stack operations

  • *D x = Duplicate top value of main stack and returns x.
  • *S x = Swap top 2 values of main stack and returns x.
  • *Z x = Discard top value of main stack and returns x.
  • *> x = Push x to main stack and return x.
  • *< x = Pop a value from main stack and return that value, or return x if is no more left on main stack.

Miscellaneous

  • ,? x = Check type of x. 0=null, 1=code-block, 2=number, 3=label-name, 4=variable-pointer, 5=string, 6=brainfuck, 7=list, 8=quantum-pointer, 9=regular-expression, 10=object, 11=continuation, 12=boolean, -1=other.
  • ,& x y = Concatenation of x and y. They can be code-blocks or strings or lists or brainfucks (but they have to be both the same type).
  • ,| x = Count items in a list, characters in a string, or entries (number of tapes) in a stack of tapes in a variable.
  • +S x y z = Change all of the substitution numbered y (y is a number) in the code-block x (including sub-blocks) to the value z.
  • ,S x y z = Change all of the substitution numbered y (y is a number) in the code-block x (including sub-blocks) to the substitution with number z.
  • ,: x = Ignores x, returns a copy of the code-block that is currently executing.
  • .: x = Pop a value from main stack, and returns a code-block that is same as x but the value that was popped is pushed to the main stack at the start of the code (after an argument to that function has been pushed).
  • *: x = Converts x to a boolean value. Booleans remain unchanged, zero is false, null is false, empty code-blocks/lists/strings/variables/brainfucks are false, non-empty variables use the value at the tape pointer to determine true/false, label names that don't exist in the current context are false, regular expressions representing an empty set are false, quantum values are observed and 0=false and 1=true, objects with all properties set to null are false, and everything else is true.
  • *? x y z = Convert x to boolean (using *: function) until is boolean, and then returns y if is true, z if is false.
  • *= x y = True if x equals y exactly, otherwise false.

Conversion of other programs to SoT

You can convert other programs to SoT, depending on what programming language it was written in.

Unlambda

  • The program starts with =C=<a'C' to initialize the varible to store the current character.
  • s k i v c converts to .s .k .i .v .c so you just need to put a dot before it.
  • Output is {>."x"} where x is character to output.
  • d function: You have to use {% before the first argument and %} after the first argument in order to create it.
  • e function: It is {?.}
  • @ function: In Unlambda it reads a character and makes it the current character. In SoT it is {%`%``/?<?`<='C'>,^.i.v}
  • ?x to compate a character read is {%`%``/?`/="x">='C'.i.v} with "x" replaced with the character you want to check.
  • | to reprint character read is: {%`%``/?<?>='C'``+S{>._0_}#0#>='C'.v}

Underload

  • ~ in Underload is /S^ in SoT.
  • : in Underload is /D^ in SoT.
  • ! in Underload is /Z^ in SoT.
  • * in Underload is %`<&%% in SoT.
  • ( in Underload is %{ in SoT.
  • ) in Underload is } in SoT.
  • a in Underload is %``-S{%{_0_}}#0#% in SoT.
  • ^ in Underload is ;% in SoT.

Replacing all S commands with ! (sacrificing output) makes SoT Turing-complete.