Tesseract

From Esolang
Jump to navigation Jump to search
Tesseract
Designed by User:MaroonCoffee
Appeared in 2024
Memory system stack-based
Dimensions two-dimensional
Computational class Total
Reference implementation https://github.com/MaroonCoffee/tesseract
Influenced by Cube, Befunge
File extension(s) .tes .cube .dewy

Tesseract

Tesseract is an esoteric programming language designed to run code on a 4D hypercube. Inspired by Ethan Muchnik's Cube: https://github.com/EthanMuchnik/Cube-Language-Interpreter. Tesseract can run its own file type '.tes', as well as Cube's '.cube' & '.dewy' natively by converting a Cube file into a tesseract.

Like its predecessors, Tesseract is run on a 2D grid (in this case it's a 2D representation of a tesseract). A cursor is placed at some point on the grid and moves in a direction until its direction is changed. Along the way if the cursor runs into any symbols, it will add them to the appropriate stack and carry out operations in this way. For more information see Cube (linked above), and Befunge: https://esolangs.org/wiki/Befunge

Example

The following text file represents a simple example of Tesseract code:

/*3`````````````````````````````````````````````````````````````````*/
/*````````````````````````(|v```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*``````````````````  {```  <```   `````````````````````````````````*/
/*``````````````````   ```   ```   `````````````````````````````````*/
/*``````````````````   ```   ```   `````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*`````````   ```````````````````````````   ````````````````````````*/
/*`````````   ```````````````````````````   ````````````````````````*/
/*`````````   ```````````````````````````   ````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*```   ```   ```   ```````````````   ```   ```   ``````````````````*/
/*```   ```   ```   ```````````````   ```   ```   ``````````````````*/
/*```   ```   ```   ```````````````   ```   ```   ``````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*`````````   ````````````   ````````````   ````````````````````````*/
/*`````````   ````````````   ````````````   ````````````````````````*/
/*`````````   ````````````   ````````````   ````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*`````````   ``````v"r```ipt```"} ``````   ````````````````````````*/
/*`````````   ``````>"c```S o```m"v``````   ````````````````````````*/
/*`````````   ``````   ```{"D```e"<``````   ````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*`````````  ;````````````   ````````````   ````````````````````````*/
/*`````````   ````````````   ````````````   ````````````````````````*/
/*`````````   ````````````   ````````````   ````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*```65+```"  ```"v ```````````````   ```   ```   ``````````````````*/
/*```   ```  v``` < ```````````````   ```   ```   ``````````````````*/
/*```   ``` ^:```   ```````````````   ```   ```   ``````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*`````````  )```````````````````````````   ````````````````````````*/
/*`````````   ```````````````````````````   ````````````````````````*/
/*`````````   ```````````````````````````   ````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````` >v```````````````````````````   ````````````   `````````*/
/*`````````  =```````````````````````````   ````````````   `````````*/
/*`````````  1```````````````````````````   ````````````   `````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   `````````````````````   ```   ```   ```*/
/*````````````````````````   `````````````````````   ```   ```   ```*/
/*````````````````````````   `````````````````````   ```   ```   ```*/
/*``````````````````````````````````````````````````````````````````*/
/*``````````````````   ```   ```   `````````````````````   `````````*/
/*``````````````````   ```   ```   `````````````````````   `````````*/
/*``````````````````   ```   ```   `````````````````````   `````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   ```````````````````````````   `````````*/
/*````````````````````````   ```````````````````````````   `````````*/
/*````````````````````````   ```````````````````````````   `````````*/
/*``````````````````````````````````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*````````````````````````   ```````````````````````````````````````*/
/*``````````````````````````````````````````````````````````````````*/

This Program prints "Hello World!", "Tesseract: 8x better than Cube!", and "Debug Script" being printed as individual characters.

Besides its unique geometry, Tesseract's main gimmick is its use of dual syntax. Depending on the mode, Tesseract swaps between Befunge syntax and Cube syntax. The following is a list of features and commands in Tesseract:

Both Modes

Cmd Description
{ The wormhole operator. Moves the cursor to the cube face corresponding to the cursor's current cube face in 4D and changes x-direction if applicable. Additionally, due to a quirk in space-time, toggles the language mode from Cube to Befunge and vice versa. We speculate this could be due to a possible shift forwards or backward in time by about 30 years.
} Flexes on Cube.

Cube Mode

(from: https://github.com/EthanMuchnik/Cube-Language-Interpreter)

  • Direction gets changed when switching cube faces based on the geometry of a cube
  • LetNum Stack: Stores letters and numbers
  • Literal letters and numbers are pushed to LetNum stack (no v or space as these are reserved for down arrow and empty space respectively)
  • Operation Stack: + - \ * / %
  • Characters placed in correct stack automatically
  • Operations are only executed if key character has been read and mode is enabled
Cmd Description
( Begins execution at this point
) Subtraction: Ends execution at this point
> Turn right
< Turn left
^ Turn up
v Turn down
" Key character that swaps do operation / don't (starts on don't)
| Prints "Hello World"
; Pops num off "n" then print next n chars
, Takes input and adds characters in order on to stack
\ Clears both stacks
= Pops top off and prints ascii character of it
! Switch stack that stack_modifiers modify (starts on LetNum Stack)
# Duplicate top character on stack (chosen by !)
$ Pops num off "n" then duplicates the nth character on ! stack to top
& Pops num off "n" then deletes the nth character on ! stack
@ Pops nums off "m" and "n" then swaps values on ! stack
? Pops nums off "em" and "n". Turn right if m > n, left if m < n, straight =
: Pops nums off "n" then until colon hit n times turn left, afterward keep straight

Befunge Mode

(from: https://esolangs.org/wiki/Befunge)

  • LetNum Stack: Stores numbers
  • Literal numbers are pushed to LetNum stack
  • Operations are executed immediately and not pushed onto the Operation stack
Cmd Description
+ Pops 2 ints off the LetNum stack (m, n), then pushes m+n to the LetNum stack
- Befunge Mode: Pops 2 ints off the LetNum stack (m, n), then pushes m-n to the LetNum stack
* Pops 2 ints off the LetNum stack (m, n), then pushes m*n to the LetNum stack
/ Pops 2 ints off the LetNum stack (m, n), then pushes m/n to the LetNum stack
% Pops 2 ints off the LetNum stack (m, n), then pushes m%n to the LetNum stack
! Pops an int off the LetNum stack (n). If n is 0 pushes 1 onto the LetNum stack, otherwise pushes 0
` Pops 2 ints off the LetNum stack (m, n). If n > a pushes 1 onto the LetNum stack, otherwise pushes 0
> Move right
< Move left
^ Move up
v Move down
? Move in a random direction
_ Pops an int off the LetNum stack (n). Moves the cursor right if n=0, otherwise moves the cursor left
| Pops an int off the LetNum stack (n). Moves the cursor down if n=0, otherwise moves the cursor up
" Starts string mode, where all characters are pushed to the LetNum stack as their ascii value until the next '"' is read (string mode has no affect in cube mode)
: Duplicates the top character on the LetNum stack
\ Swaps top two characters on the LetNum stack
$ Pops an int off the LetNum stack and discards it
. Pops an int off the LetNum stack (n) and prints it as an integer followed by a space
, Pops an int off the LetNum stack (n) and prints it as an ascii character
# Skips the next cell's execution
g Pops 2 ints off the LetNum stack (y, x) and pushes the ascii value of the character at (x, y) in the current tesseract face to the LetNum stack. Pushes 0 in the event (x, y) is out of bounds
p Pops 3 ints off the LetNum stack (y, x, v) and changes the character at (x, y) in the current tesseract face to the character with ascii value v. Does nothing in the event (x, y) is out of bounds
& Gets an int from the user and pushes input onto the LetNum stack
~ Gets an char from the user and pushes ascii value onto the LetNum stack
@ Terminates the program
09 Push corresponding number onto the Letnum stack

Traversal

Like Cube, when the cursor reaches the end of one side of a cube it wraps back around to the other side and its visual direction may appear to have changed (though it's really a change in perspective).

Traversal of a cube
Traversal of a cube

Tesseract's equivalent wrap-around gimmick is with its wormhole operator, which warps the cursor from one cube face to another cube face based on the geometry of a tesseract. Each square face of a tesseract has a single corresponding face that occupies the same space as the first. For reference, here's a tesseract unfolding: https://en.wikipedia.org/wiki/Tesseract

Traversal of a tesseract
Traversal of a tesseract

Features (stolen from Cube)

  • 2D representation of 4D coding interface.
  • Code "intuitively" represents an unfolded cube
  • Input/Output Functionality
  • Is primarily run from two Stacks(Operation Stack and Char Stack)
  • Special Functionality When Crossing Between Cubes
  • One of the few languages that can be run from more than one extension(.tes, .cube and .dewy)
  • Exclusively Coded in C Meaning Source Code is better than Cube's

Building

Requirements:

  • gcc
  • make

Supported Systems:

  • Windows 10/11
  • GNU/Linux
  • MacOS (untested)

Install Tesseract and Run Tesseract or Cube File

make
./tesseract file.tes -d (debug flag optional)
./tesseract cube_file.cube -d

Documentation

For more information on how Cube or Befunge works, check out Cube's documentation and Befunge's esolang wiki page:

Additional Documentation/Links

Check out the Github repository: (https://github.com/MaroonCoffee/tesseract/)

Credits

  • Elijah Rosen - Created Tesseract
  • Ethan Muchnik - Created Cube (and the README I copied from a lot :p)
  • Chris Pressey - Created Befunge