Tru

From Esolang
Jump to navigation Jump to search

Tru is an esoteric programming language of brackets using prefix-free code, designed by User:Swc.

The language runtime has two built-in stacks. The instructions to interact with those stacks are represented by using only bracket characters.

Although the instructions only consist of brackets, the instructions can be put together without losing meaning they are prefix-free. Concretely, no instruction is a prefix of another.

The following prints "Hello, world!":

(0)(10)(33)(100)(108)(114)(111)(119)(32)(44)(111)(108)(108)(101)(72)>><<[<><>><<>><<]>>><<

Specification

Instructions

Below are the complete set of tru instructions.

No instruction is a prefix of another. Therefore, the instructions can be either separated by whiespaces or newlines, or put together without losing the meaning.

Cmd Description
( Start describing an integer to push
) Push the integer between the corresponding opening bracket to the current stack.
<><>><< Print character: Pop from the current stack and print the value as a UTF-8 character
<><>><> Print integer: Pop from the current stack and print the value as a number
<><>>> Integer input: Get an integer input and push to the current stack as a number
<><>< Character input: Get an integer input and push to the current stack as a UTF-8 character
>>><< End: Specify the end of the program
>>><> Move: Pop from the current stack and push to the other stack
<><< Discard: Pop from the current stack and discard
>><< Duplicate the top value of the current stack
>><> Swap the top two values of the current stack
>>>> Subtract
<<< Add
<<> Greater than
<>> Equals
><< Not
><> Select stack: Pop from the stack and set the current stack equal to the value. The stacks are indexed 0 and 1.
[ Jump: Pop the current stack and jump to the matching ] if the value is zero
] Jump: Pop the current stack and jump to the matching [ if the value is non-zero
# Comment: ignore all characters that follow for the rest of the line

Concretely, the due to the prefix-free nature of the instructions, the following are equivalent

(1)
>><<
(2)
<<<
>><<
<><>><<
(1)>><<(2)<<<>><<<><>><<

Linebreaks and spcaes

Linebreaks and spaces are permitted and ignored. However, numbers and instructions cannot be broken with linebreaks or spaces.

# Okay
(
  10
)

# Not okay
(
1
0
)

# Okay
>><<

# Not okay
>>
<<


Examples

Hello, World!

(0)(10)(33)(100)(108)(114)(111)(119)(32)(44)(111)(108)(108)(101)(72)>><<[<><>><<>><<]>>><<

Fibonacci

# print 25th Fibonacci number
(1)(25)(1)><>(1)(0)><>(1)>>>>>><<[(0)><>(1)>>>>>><<[>><>(1)><>>><<(0)><>>>><>(1)><><<<>><>>>><>(0)><>>><>(1)>>>>>><<](0)](1)><><><>><>>>><<

Quine

(9999)(60)(60)(62)(62)(62)(60)(60)(62)(60)(93)(60)(60)(62)(62)(62)(60)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(60)(60)(62)(62)(93)(41)(0)(40)(62)(60)(62)(41)(0)(40)(41)(7777)(40)(62)(60)(62)(41)(1)(40)(60)(60)(62)(62)(60)(62)(60)(62)(60)(62)(62)(62)(60)(60)(62)(62)(62)(60)(62)(41)(0)(40)(91)(60)(60)(62)(62)(60)(62)(41)(1)(40)(93)(41)(0)(40)(62)(60)(62)(41)(0)(40)(41)(8888)(40)(62)(60)(62)(41)(1)(40)(62)(60)(62)(62)(60)(62)(60)(62)(60)(62)(62)(62)(60)(60)(62)(62)(62)(60)(62)(41)(0)(40)(91)(60)(60)(62)(62)(62)(62)(60)(41)(2)(40)(62)(60)(62)(41)(1)(40)(62)(60)(62)(62)(62)(60)(60)(60)(62)(60)(62)(41)(0)(40)(62)(60)(62)(62)(62)(62)(62)(60)(41)(40)(40)(60)(60)(62)(62)(62)(60)(62)(62)(62)(62)(62)(60)(41)(7777)(40)(62)(60)(62)(41)(1)(40)(91)(41)(1)(40)(41)(1)(40)(41)(8888)(40)(62)(60)(62)(41)(1)(40)(60)(60)(62)(60)(93)(93)(41)(0)(40)(60)(60)(62)(62)(60)(62)(60)(41)(41)(40)(62)(60)(62)(62)(60)(62)(60)(62)(60)(62)(62)(62)(60)(60)(62)(62)(60)(60)(62)(62)(60)(62)(60)(41)(40)(40)(62)(60)(62)(62)(91)(60)(60)(62)(62)(60)(60)(62)(62)(62)(60)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(60)(60)(62)(62)(62)(60)(62)(41)(1)(40)(91)(41)(1)(40)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(62)(60)(62)(41)(0)(40)(60)(60)(62)(62)(60)(62)(60)(41)(41)(40)(62)(60)(62)(62)(60)(62)(60)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(60)(60)(62)(62)(60)(62)(60)(41)(40)(40)(60)(60)(62)(60)(93)(93)(41)(0)(40)(62)(60)(62)(62)(62)(62)(60)(62)(62)(91)(60)(60)(62)(62)(60)(60)(62)(62)(62)(60)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(60)(60)(62)(62)(62)(60)(62)(41)(0)(40)(91)(41)(1)(40)(60)(60)(60)(41)(1)(40)(41)(9998)(40)(62)(60)(62)(41)(1)(40)(1)><>(9998)(1)<<<(1)[(0)><>>><<(9998)(1)<<<<>>><<>><<[>><>>>><>(0)]]<><<(40)<><>><<(9998)(1)<<<<><>><>(41)<><>><<(0)><>(9998)(1)<<<(1)[(1)><>>><<(9998)(1)<<<<>>><<>><<[>><>(40)<><>><<>><<>>><><><>><>(41)<><>><<(0)]]<><<(1)><>(8888)(1)(1)[(1)><>(7777)<>>>>><>>><<(40)<>>>>><>(0)><><<<>>><>(1)><>(2)<>>>><<[(0)><>>><<>>><><><>><>(1)><>(8888)(0)><>(0)](1)><>><<[(0)><>>><<>>><><><>><<(1)><>(7777)(0)><>(0)]>><<(9998)(1)<<<<>>><<]<><<>>><<


External resources