# 4est

4est is a tree based esolang by User:BoundedBeans featuring nested tree data structures. This was the first esolang he created, so it is quite bad.

## Storage

The way it stores data is in a variety of places: One or more outer trees, each node containing an inner tree. The inner trees are confusingly referred to as forests (NOT the outer trees), while individual VALUES in the inner tree are referred to as trees. There can be multiple outer trees, known as continents, stored in an ArrayList. There can be multiple ArrayLists, known as realities, stored in YET ANOTHER tree structure, because everybody knows that all the realities of the multiverse are folded together into a GIANT PRIMORDIAL PLUM TREE.

## Instructions

Instructions are separated by a period followed by a tab, a space, or a newline. All other whitespace is ignored. “//“ can be used to comment out things until a newline.

### Basic operations

`Visit the [list of ordinal numbers] forest.` Create the outer tree structure corresponding to the node numbers of each level, every node with a smaller number, and the parents of each level and the smaller parent numbers. If a tree already exists, add to the bottom level. Be careful with this command, because this can get big really fast. Sets them all to a tree containing only a root node. For example: `Visit the 4th 2nd 5th forest.` Creates a tree with a root node having 4 children, each having 2 children, each having 5 children. This creates a total of (4*2*5)+(4*2)+(4)+1 = 53 nodes.

`Propagate the [list of ordinal numbers] forest (number) times.` Adds number children to the coordinates in the outer tree.

`Visit the [list of ordinal numbers] tree.` Create an inner tree in a similar manner to the Visit Forest command, but nested inside the outer tree and with all values set to 0.

`Propagate the [list of ordinal numbers] tree (number) times.` Adds number children to the coordinates in the inner tree.

`Fly over the [list of ordinal numbers] forest.` Moves the pointer to the coordinates of the ordinals in the outer tree.

`Fly over the [list of ordinal numbers] tree.` Moves the pointer to the coordinates of the ordinals in the inner tree.

`Axe the forest.` Add one to the outer pointer.

`Cut the forest.` Subtract one from the outer pointer.

`Mine the forest.` Move the pointer to the parents in the outer tree.

`Chop the (ordinal) forest.` Move the pointer to the ordinal child in the outer tree.

[Any one of the above four commands but with "tree" instead of "forest"] Do the same thing for the inner pointer.

`Graft the tree [number] times.` Set the value at the current pointer positions to number.

`Graft the [list of ordinals 1] tree in the [list 2] forest to the [list 3] tree in the [list 4] forest.` Sets the value at outer coordinates in list 3 and inner coordinates list 4 to the value of the coordinates of list 1 and 2.

`Plant the [list of ordinal numbers] sapling around the [list 2] tree.` Add the number at coordinates list 1 to coordinates list 2. (inner tree)

`Destroy the [list of ordinal numbers] sapling around the [list 2] tree.` Subtract the number at coordinates list 1 from coordinates list 2. (inner tree)

`Spray the [list of ordinal numbers] sapling around the [list 2] tree.` Multiply the number at coordinates list 1 by coordinates list 2 and store the result in coordinates list 2. (inner tree)

`Decimate the [list of ordinal numbers] sapling around the [list 2] tree.` Divide the number at coordinates list 1 by coordinates list 2 and store the result in coordinates list 2. (inner tree)

### Loops and if-else

All loops and if-else start statements act as if they include the opening bracket within.

`Prune the [list 1 of ordinals] tree in the [list 2] forest.` Do the coordinates as usual, and start a loop with it as the loop counter. This is a for loop.

`While the [list 1 of ordinals] tree in the [list 2] forest is (conditional) the [list 3] tree in the [list 4] forest.` Continue the loop as long as a conditional is true between the two values.

`If the [list 1 of ordinals] tree in the [list 2] forest is (conditional) the [list 3] tree in the [list 4] forest.` Like a while loop, but only goes once if true, does not go if false. An if statement is equivalent to this.

`Or else.` Else. Else if can be accomplished by putting an if statement inside of an else statement.

`Sterilize tools.` Closing brackets.

### Conditionals

```= as strong as
!= incomparable to
< less well-rooted than
> more well rooted than
<= containing less fruit than
>= containing more fruit than
```

### Input/output

`Take recommendations.` Input a number into the value at the current pointer positions.

`Take advice.` Input the ascii/unicode value of a character.

`Give recommendations.` Output the value at the current pointer positions as a number.

`Give advice.` Output the value at the current pointer positions as a character.

`Ask for help.` Continue looping until there is no more input.

For these, a file path can also be specified by using "at", "to", or "from" followed by "PATH:" then the full file path, or the better "REL:" followed by the path of a file in the same folder, without the path leading to the folder.

### Tree structure manipulation

This takes the form of "Birdwatch" commands for the outer tree, and "Fishwatch" for the inner tree.

`Birdwatch finch.`/`Fishwatch carp.` Duplicates the lowest level of the tree (if inner tree, specified by the pointer), with every parent having one child completely copied. Doing this on the outer tree will copy all inner trees and their values on the lowest level, while doing this on the inner tree copies the value. Useful for duplicating large sequences of values.

`Birdwatch hawk.` Only for outer trees. Duplicates the structure of the inner trees, but not the values inside.

`Birdwatch cardinal.` Only for outer trees. Puts the entire structure of the outer trees into the inner tree at the outer pointer, but sets all the values to 0. WARNING: This deletes all existing values in the inner tree.

### Reality manipulation

`Enter new continent.` Creates a new outer tree and assigns it an index based on when you added it. Does not switch list pointer to the outer tree. Starts with only a root node with a tree with only a root node assigned to 0 inside.

`Sail west (number) hours.` Enters the outer tree with number index. Now, any operations will apply to this outer tree, not the previous one.

`Grab possessions before traveling.` Assign the carryover integer to the value at the current outer and inner pointers.

`Rest.` Put the carryover integer into the value at the current outer and inner pointers in the new tree.

`Nuke continent (number).` Removes the outer tree with number index. Pushes everything past one level back. WARNING: This deletes everything, including the values!

`Explore for (number) hours.` Adds a continents at the specified index, pushing everything else forward. Not allowed if there are no continents past it since it would just be empty space and the programming language would throw an error.

### Primordial manipulation

All take the form of "Plumcommand", then the command, then any arguments. The plum tree is primordial and therefore only sees the basic rules which govern all realities; it will not understand your verbose English statements.

`Plumcommand pointerparent.` Moves primordial pointer to the parent.

`Plumcommand pointerchild (number).` Move primordial pointer to the numberth child.

`Plumcommand pointersibling (number). ` Move primordial pointer number siblings to the right. Negative numbers will move it to the left.

`Plumcommand createchild (number).` Create number child nodes to the current pointer. If it already has children, it will just make number more children.

`Plumcommand ambassadorget (x) (y) (z).` Take the number at the current pointers and put it in the dimensional array in the indexes specified. The indexes can only be from 0-3, inclusive, meaning there can be a maximum of 64 ambassador values.

`Plumcommand ambassadorput (x) (y) (z).` Take the number from the dimensional array at the index and put it as the value at the current pointers.

## Special ordinals

While normal ordinals are great for specifying coordinates, they lack the ability to do it dynamically (using a variable as the coordinate). Using parenthesis, we can do things like this.

```(1st 5th 7th)th
```

This uses the value in the coordinates 1 5 7 in the inner tree at the current outer pointer.

```(<6th 2nd 8th> 2nd 9th)th
```

This goes to the coordinates 6 2 8 in the outer tree, uses that inner tree, then the coordinates 2 9 in that inner tree, and uses it as the value for the ordinal.

And yes, nested parenthesis work too.

```(<(<8th 2nd> 7th 4th)th 2nd> 6th 4th (<2nd 3rd> 2nd 7th))
```

Uses the coordinate 8 2 in the outer tree, then the 7 4 coordinates in the inner tree, uses the value in there as the first coordinate, along with 2, then the inner tree at that coordinate is used, which the coordinates 6 4 are used, then the third coordinate is the value of coordinates 2 3 in the outer tree, and the coordinates 2 7 in the corresponding inner tree.

This is quite complicated, but it can be used with as many levels of parenthesis as you desire.

We can also specify the root node by using `mother`. As in `Fly over the mother forest.` Mother is special because it can't be used with any other ordinals on the same level. The root node in the outer tree can still have ordinals in the inner tree. Coordinates in the outer tree can still have accessible root nodes in the inner tree. For example:

```Graft the 7th 9th 15th tree in the mother forest to the mother tree in the 3rd 5th forest.
```

## Programs

### Hello world

```Visit the 12th tree.
Fly over the 1st tree.
Graft the tree 72 times.
Fly over the 2nd tree.
Graft the tree 101 times.
Fly over the 3rd tree.
Graft the tree 108 times.
Graft the 3rd tree in the mother forest to the 4th tree in the mother forest.
Fly over the 5th tree.
Graft the tree 111 times.
Fly over the 6th tree.
Graft the tree 32 times.
Fly over the 7th tree.
Graft the tree 119 times.
Graft the 5th tree in the mother forest to the 8th tree in the mother forest.
Fly over the 9th tree.
Graft the tree 114 times.
Graft the 3rd tree in the mother forest to the 10th tree in the mother forest.
Fly over the 11th tree.
Graft the tree 100 times.
Fly over the 12th tree.
Graft the tree 33 times.

Visit the 1st forest.
Fly over the 1st forest.
Visit the 3rd tree.
Fly over the 1st tree.
Graft the tree 13 times.
Fly over the 2nd tree.
Graft the tree 1 times.
Fly over the 3rd tree.
Graft the tree 1 times.
While the 2nd tree in the 1st forest is less well-rooted than the 1st tree in the 1st forest.
Fly over the mother forest.
Fly over the (<1st> 2nd)th tree.
Fly over the 1st forest.
Fly over the 2nd tree.
Plant the 3rd sapling around the 2nd tree.
Sterilize tools.
```

### Calculator

```Visit the 3rd tree.
Propagate the 1st tree 3 times.
Propagate the 2nd tree 4 times.
Propagate the 3rd tree 5 times.

Fly over the 1st 1st tree
Take recommendations.
Fly over the 1st 2nd tree.
Fly over the 1st 3rd tree.
Take recommendations.

Fly over the 2nd 1st tree.
Graft the tree 43 times.
Fly over the 2nd 2nd tree.
Graft the tree 45 times.
Fly over the 2nd 3rd tree.
Graft the tree 42 times.
Fly over the 2nd 4th tree.
Graft the tree 47 times.

Fly over the 3rd 1st tree.
Graft the tree 69 times.
Fly over the 3rd 2nd tree.
Graft the tree 82 times.
Graft the 3rd 2nd tree in the mother forest to the 3rd 3rd tree in the mother forest.
Fly over the 3rd 4th tree.
Graft the tree 79 times.
Graft the 3rd 2nd tree in the mother forest to the 3rd 5th tree in the mother forest.

If the 1st 2nd tree in the mother forest is as strong as the 2nd 1st tree in the mother forest.
Plant the 1st 3rd sapling around the 1st 1st tree.
Sterilize tools.
Or else.
If the 1st 2nd tree in the mother forest is as strong as the 2nd 2nd tree in the mother forest.
Destroy the 1st 3rd sapling around the 1st 1st tree.
Sterilize tools.
Or else.
If the 1st 2nd tree in the mother forest is as strong as the 2nd 3rd tree in the mother forest.
Spray the 1st 3rd sapling around the 1st 1st tree.
Sterilize tools.
Or else.
If the 1st 2nd tree in the mother forest is as strong as the 2nd 4th tree in the mother forest.
Decimate the 1st 3rd sapling around the 1st 1st tree.
Sterilize tools.
Or else.
Fly over the 3rd 1st tree.