.box

From Esolang
Jump to navigation Jump to search

.box (pronounced 'dotbox') is an esoteric programming language created by User:Fr34k and E. Grouse in 2009. It operates using only dots and linefeed.

Workflow

Programming in .box can be a bit tricky. Due to the fact that it only uses dots and linefeed to operate, it has taken on a special concept, which can also be found in Whitespace. It works like this, before each command, a series of operators indicates what kind of operation is coming next. For example, if one were to define a variable, it would be typed like this, in pseudo-code

using variables
assign variable
variable name
variable value
stop using variables

One thing that is special about programming like this in .box is, however, every time you indicate what kind of operations you are going to do, you must specify this on a line with an odd number. Everything else goes on lines with even numbers. Which means, if we refer to the above pseudo-code, that the commands 'using variables' and 'stop using variables' must both be written on odd lines and every code in between must be written on even lines. However, if one would start assigning something else, in a middle of an assignment, this must also be written on an odd line. For example

using functions *
define function
function name
define function arguments
using variables *
define variable
variable name
stop using variables *
stop defining function arguments *
using variables*
return variable
stop using variables *
stop using functions *

This might seems like gibberish right now. But in time it will make perfect sense. In the above code, every line that ends with an asterisk must be written on a line with an odd number. Every other line must be on an even line. Also, when referring to functions or variables, one does so with a number of dots. You could think of it as indexes in an array. With that said, lets move on to the actual commands!

Commands

When using different types of commands, you use different kind of indicators, written on lines with odd numbers (can it be said enough?). In the structure sections, every line ending with an asterisk should be placed on a line with an odd number.

Variables

Indicators

.      Start using
..     Stop using

Commands

.      Define a variable
..     Call a variable

Structure

indicator *
command
index
value
indicator *

Functions

Indicators

...    Start using
....   Stop using

Commands

.      Define a function
..     Call a function
...    Start conditions
....   End conditions
.....  Start statements
...... End statements

Structure

indicator *
command
index
conditions (leave blank if none is used)
statements
indicator *

Built-in functions

Indicators

.....  Start using
...... Stop using

Commands

.      If
..     Else
...    For
....   While
.....  Break

Structure

indicator *
command
condition
statement
indicator *

Relational and equality operators

Indicators

.......   Start using
........  Stop using

Commands

.         Is equal to
..        Is not equal to
...       Is greater than
....      Is smaller than
.....     Is greater than or equal to
......    Is smaller than or equal to

Structure

indicator *
first argument
command
second argument
indicator *

Arithmetic operators

Indicators

.........   Start using
..........  Stop using

Commands

.     Addition
..    Subtraction
...   Multiplication
....  Division

Structure

indicator *
first argument
command
second argument
indicator *

Numbers

Indicators

...........   Start using
............  Stop using

Commands

There does not exist a specific command. The number of dots between the two indicators are equivalent to the number.


Examples

Below follows a series of detailed examples and explanations. I'll do my best to explain how every program works and what is happening. For clarity, I will also be writing the line numbers.

Using variables

Defining a variable

01   .            // Using variables
02   .            // Define a variable
03
04   .            // Variable index 1
05   ...........  // Start using numbers
06   ..           // Value for variable index 1 is now 2
07   ............ // Stop using numbers
08
09   ..           // Stop using variables

As you can see, a .box program can contain commands that look the same, but operates differently, depending on what line number they have been placed on. (Another important thing to keep in mind is, that as for now, .box does not support variables with string support.)

Calling a variable

In this example, I'm first going to create a variable, then create another variable containing the first variables value.

01   .            // Using variables
02   .            // Define a variable
03
04   .            // Variable index 1
05
06
07   ...........  // Start using numbers
08   .            // Value for index 1 is 1
09   ............ // Stop using numbers
10
11   .            // Define a new variable
12   ..           // at index 2
13
14   ..           // Call a variable
15
16   .            // Call variable index 1
17   ..           // Stop using variables

As you may have noticed, .box programs easily gets very complex very quickly and it extremely easy getting lost in the source code. As for now, you'll have to do with these examples until I can be arsed on writing down some more. You give it a try, it's very confusing.

Using arithmetic

Using arithmetic can in .box be both simple and complex in comparison to other .box programs. In this example we will define two variables, then adding them together in a third variable.

01 .
02 .
03
04 .
05 ...........
06 ..
07 ............
08 ..
09 ..
10 
11 .
12 .
13 
14 ..
15 ...........
16 ...
17 ............
18 ..
19 ..
20 
21 .
22 .
23 
24 ...
25 .........
26 
27 .
28 ..
29 
30 .
31 ..
32 .
33 .
34 ..
35 
36 ..
37 ..
38
39 .........
40
41 ..

Using functions

Defining and calling a function

In this example, I will create a function that takes two arguments, adds them and puts them in a new variable. I also define two variables and use them in the function I created. A normal language example would look something like this

function add(a, b){
   c = a + b;
}
a=2;
b=3;
add(a, b);

So without further ado, here's the source

01 ...				// Start using functions
02 .				// Define a function 
03
04 .				// Function index 1
05
06 ...				// Start conditions
07 .				// Start using variables
08 .				// Define a variable
09 
10 .				// Variable index 1
11
12 				// Is left blank
13 ..				// Stop using variables
14 
15 .				// Start using variables
16 .				// Define a new variable
17
18 ..				// Index 2
19
20				// Is left blank
21 ..				// Stop using variables
22 ....			// End conditions
23
24 .....			// Start statements
25 .				// Start using variables
26 .				// Define a variable
27
28 ...				// Index 3
29 .........		// Start using arithmetic
30
31 .				// Start using variables
32 ..				// Call a variable
33
34 .				// Call index 1
35 ..				// Stop using variables
36 .				// Addition
37 .				// Start using variables
38 ..				// Call a variable
39
40 ..				// Call index 2
41 ..				// Stop using variables
42 
43 ..........		// Stop using arithmetic
44 
45 ..				// Stop using variables
46 ......			// End statements
47 ....			// Stop using functions
48 
49 .				// Start using variables
50 .				// Define a variable
51 
52 .				// Variable index 1
53 ...........     // Start using numbers
54 ..				// 2
55 ............	// Stop using numbers
56 
57 ..				// Stop using variables
58 
59 .				// Start using variables
60 .				// Define a variable
61
62 ..				// Variable index 2
63 ...........     // Start using numbers
64 ...				// 3
65 ............	// Stop using numbers
66 
67 ..				// Stop using variables
68 
69 ...				// Start using functions
70 ..				// Call a function
71
72 .				// Call function 1
73 
74 ...				// Start conditions
75 .				// Start using variables
76 ..				// Call a variable
77
78 .				// Call index 1
79 ..				// Stop using variables
80 
81 .				// Start using variables
82 ..				// Call a variable
83
84 ..				// Call index 2
85 ..				// Stop using variables
86 ....			// End conditions
87 ....			// Stop using functions