Dot Box 2

Published 1:35am on 5th June 2019
by Max Zlotskiy

One of my favorite esoteric programming languages is .Box (pronounced "dot box"). It was created in 2009 by Esolangs user Fr34k and E. Grouse. What amazes me about .Box is that it operates using only dots (.) and linefeed, but it allows for complex functional programming language constructs to evolve from its binary code.

Commands

Here is a list of commands. Most of them have been changed to be more consistent with others in their indicator group. In addition, I added some new commands to make the language work with more types of data than just numbers.

Variables

The general order of instructions is

start using variables
command
variable name
value
stop using variables

Value is optional. It is not a number of dots, rather, it is obtained by either getting the value of another variable, a reference to another variable, evaluating an arithmetic/boolean expression, or creating a number. If it is not provided, it is assumed to be null. The following are the commands, with the order corresponding to the number of dots:

  1. define/set variable (value will be the new value of this variable). If the stop indicator comes before a value is provided, then the variable will simply be declared and not initialized.
  2. get variable (value will be returned instead of the variable if the variable is not defined). This will return the value of this variable which can be used as the value for other commands. If the variable is a reference, then all pointers will be followed until a value is reached.
  3. dereference variable (value will be returned instead of the dereferenced scope if this variable is not defined). This can be used to access properties of an object. This command effectively changes the scope of all commands in this indicator block. Use a nested indicator block to access variables outside of the dereferenced variable.
  4. make c++ style reference to variable (value will be instantiated in dynamic memory and this variable will be the only reference to it)

Functions

Here are the commands in this indicator block:

  1. Define a function
  2. Call a function
  3. Start parameters
  4. End parameters
  5. Return

This is the outline of function definitions:

Function Indicator
Define
function name
Start Parameters
list of variable blocks...
End Parameters
list of statements...
Closing Function Indicator

The function name is a sequence of dots. This namespace is exclusive of the variable namespace, so they can share names. The body of a function is just a list of other indicator blocks.

To call a function, do the following:

Function Indicator
Call
function name
Start Parameters
list of blocks returning argument values...
End Parameters
Closing Function Indicator

To define an anonymous function, just start with the parameter definitions:

Function Indicator
Start Parameters
list of variable blocks...
End Parameters
list of statements...
Closing Function Indicator

Built-in functions

The built-in functions provide flow control to the rest of the code. The general order of instructions is

start using built-in
command
condition
statements...
stop using built-in

Statements can be any number of other indicator blocks. The rest of this block until the stop indicator is reached will be the body of the control structure. The condition should be a boolean expression.

Here are the built-ins:

  1. If
  2. Else
  3. For
  4. While
  5. Break
  6. Label

Break and Label are special commands. They don't follow the structure of the other control flow commands. The Label command is followed by a sequence of dots identifying the loop that comes after it. The Break command is found inside loop bodies and is followed by a sequence of dots identifying which outer loop to break out of. If no parameter is provided to Break, then the immediate surrounding loop is stopped.

Numbers

The number of dots between the start and end indicators will produce that number. If the dots are split among several even lines, then each line will represent one digit of the number. For example, the following are equivalent:

start using numbers
23 dots
stop using numbers

and

start using numbers
2 dots
3 dots

will both produce 23.

New Syntax

Rather than having indicators on odd-numbered lines and commands on even-numbered lines, a shorthand syntax is being introduced. The odd/even rule is being thrown out. Instead, blocks will be defined by arrows < and >. Here's an example:

<. . ..... <...... .>>

This defines a variable (named by 5 dots) whose value is the number 1.


Tags: programming language .box 2 dot box dotbox