Dot

From Esolang
Jump to: navigation, search

Dot is an esoteric programming language created by Simone Baratta and Daniele Dona in 2008 which uses an only symbol (the dot). The basic idea is that every program can be associated with a definite number. The source code of the program will contain exactly that number of dots.

Instructions

Dot has a set of 15 instructions, each of them associated to an ordinal. Programmer has the use of an array of memory cells, which is initialized with the first three instructions into the program. A pointer to the current memory cell is also available. The 15 instructions are:


Ordinal Description
1 Increments the value of the current memory cell.
2 Decrements the value of the current memory cell.
3 Increments the value of the pointer to the memory.
4 Decrements the value of the pointer to the memory.
5 End of a block of instructions.
6 Repeats a block of instructions a number of times equal to the passed parameter.
7 Sets the file with the number passed as a parameter as current input and output stream for the whole block of instructions.
8 Sets the pointer to 0 (first cell).
9 Sets to 0 a number of memory cells equal to the passed parameter (starting from the current position+1); if there are not enough cells to set until the end of the memory array, new memory cells will be created at the end of it.
10 Repeats a block of instructions until the value of the current memory cell is not 0.
11 Reads a byte from the input stream and puts it into the current memory cell.
12 Outputs the byte contained into the current memory cell to the output stream.
13 Opens a file (the name of the file is contained in the memory from the current cell to the first 0) and assigns it an ordinal (the first file opened has ordinal 1 etc.); if the file doesn't exist, it will be created.
14 Closes the file with the ordinal passed as a parameter.
15 Bonus instruction.

Programming in dot

After choosing the instructions to use and their order into the program, they are divided into blocks so that each block doesn't contain two equal instructions. Each block is associated with a series of 15 prime numbers. In each series the first prime number is associated with instruction 1, the second with instruction 2 etc. After doing this, each instruction of the block will be assigned to the corresponding prime number raised to the power with exponent equal to its position into the block (the first instruction of the block will have exponent 1, the second 2 etc.).

The number of dots to put into the program is equal to the product of every power created in this way.

Parameters

Instructions 6, 7, 9, 14 and 15 must be followed by a parameter; parameters must be specified after each block containing at least one of these instructions. For each parameter a new block of 10 prime numbers is created just after the block containing the instruction which requires a parameter. If more than one parameter is needed for the same block, the 10-prime-numbers-blocks are put in the order of the ordinal of the relative instruction (parameters for intructions 6 are always put before those for instruction 9 etc.). Parameters are considered to be binary numbers; the presence of the n-th number into the 10-prime-numbers-block means that the n-th digit of the parameter is 1; if all the digits of the parameters are set to 0 the number is considered to be 1024.

Memory

Programmer has got an array of memory cells and a pointer to the current cell, i.e. the cell on which operations are going to be executed; the first 10 numbers of the program must be used to specify how many memory cells must be initialized at the start of the program itself (the number is passed like a parameter). The pointer is set to point to the first cell. If an instruction 4 (decrease the pointer) is executed when pointer is pointing the first cell, it will be set to point to the last cell and viceversa.

Comments

Every character which is not a dot is considered to be a comment and isn't considered by the compiler.

Bonus instruction

Instruction 15 prints the whole text of "99 bottles of beer" in italian, starting from a number of bottles equal to the passed parameter.

Step-by-Step example

This program reads a character from the user, stores it into the file called "1" and then prints the whole text of "99 bottles of the wall".

Let's start from thinking about the instructions to put into the program:

3 \\We need 3 memory cells
11 \\Reads the character
3 \\Goes one cell forward
6 \\Repeats the instructions
24 \\24 times
1 \\Increments the pointer
1 \\Again
5 \\Ends of the block to repeat. Now the value of the second memory cell is 48.
1 \\Now the value of the current cell is 49 (ASCII code for "1").
13 \\Opens the file named "1" and assigns it ordinal 1.
4 \\Comes back to the first cell
7 \\Starts working on the file
1 \\File's ordinal
12 \\Puts the character into the file
5 \\Ends working on the file
14 \\Closes the file
1 \\File ordinal
15 \\Prints the lyrics of the song
99 \\Starting from 99 bottles.

Now we have to convert these instructions into a number. Let's divide the instructions into blocks (skipping the parameters):

11 3 6 1
1 5
1 13 4 7 12 5 14 15

Parameters must be converted into ten-bits binary numbers:

3=0000000011
24=0000011000
1=0000000001
99=0001100011

We have then to consider a block of 10 prime numbers for each parameter, and 15 prime numbers for each instruction:

2 3 5 7 11 13 17 19 23 29 -- the first parameter
31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 --first block of instructions
101 103 107 109 113 127 131 137 139 149 --first parameter of the first block
151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 --second block of instructions
233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 --third block of instructions
317 331 337 347 349 353 359 367 373 379 --first parameter of the third block
383 389 397 401 409 419 421 431 433 439 --second parameter of the second block
443 449 457 461 463 467 479 487 491 499 --third parameter of the third block

For each block or parameter we must now take the right numbers with the right exponent. This is how to do it with the first block:

First block is 11 3 6 1, so we must take the 11th number with exponent 1, the 3rd with exponent 2 and so on:

31^4, 41^2, 53^3, 73^1

By doing this with all the parameters and all the blocks and calculating the product of those numbers we obtain the number of dots to put into the program:

23*29*31^4*41^2*53^3*73*127*131*151*173^2*233*251^3*257^6*269^4*293^5*307^2*311^7*313^8*379*439*461*463*491*499=
215913535015369305040842444350270199050113127313895669448761896241171623806284995890414496334818749001017598099598788759021219583262203

The source code of the program must contain exactly 215913535015369305040842444350270199050113127313895669448761896241171623806284995890414496334818749001017598099598788759021219583262203 dots.