Goto Considered Harmless
- This is still a work in progress. It may be changed in the future.
Goto Considered Harmless is an esoteric programming language created by User:Ninesquared81. It is named after the conditional jump operation, which is the language's only control flow construct.
The language has 4 core operations and 3 I/O operations, for a total of 7. The only available memory is an unbounded array of signed 64-bit cells. The language also exposes an instruction pointer and data pointer to the user, hereafter referred to as ip and dp, respectively.
||If the current cell is zero, increment dp, otherwise, offset ip by current cell value.|
||Swap the current cell with the previous cell, then decrement dp.|
||Add value of dp to current cell.|
||Subtract value of dp from current cell.|
||Read a single character from stdin and store it in the current cell.|
||Print the value of the currrent cell as a character.|
||Print the value of the current cell as an integer.|
All other characters are ignored. Note that although these characters are ignored, they are not entirely insignificant, since
? makes a relative jump and ip points directly into the source string, so non-instruction characters count towards the characters being jumped over.
? instruction can set ip as an invalid index. If ip becomes negative, it is reset to zero before the next instruction is evaluated. If it is set to some value past the end of the program's source string, the program will exit.
Explanation: The 0th cell is initially 0, so
? skips to cell 1. Cell 1 is set to 0 - 1 = -1, and so
? jumps back to the start of itself and loops forever.
????????????????????????????????????????????????,-# ?????????????+? <<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<<<<<<<-+#-?
Note: the space (or some other character) on the second line is required.
Explanation: We increment dp to point at cell 48, which receives the user's input. dp (48) is then subtracted from this, leaving either 0 or 1. In the case of 0, dp is again incremented to 61, otherwise it stays at 48. At
?+? (middle of second line), for input 0, cell 61 is set to 61, which is used to jump out of the program (which exits the program). If the input was 1, however, the
+ instruction is jumped over, and ip skips over only the space character (since the current cell is still 1). Then, dp is decremented to 5, with cell 5 now containing 1. 5 is subtracted and then added to the cell, leaving it as 1 (the reason for this will become clear soon). The value in the cell is then printed as a number. 5 is subtracted from the cell again, leaving it as -4, which is used as the offset for the jump in the
? instruction, which lands ip back to just before the
+ instruction. Of course, 5 is added to the cell again, restoring the value of 1, which is printed, then 5 is subtracted,
? jumps back to