Codesick

From Esolang
Jump to navigation Jump to search

Codesick (COncatenate, DEreference and StrIng-cheCK) is an esolang created by User:TBPO when it was sick from coding too long. It's an OISC, but instead of bits or numbers, there are... strings.

Memory

There is an infinie namespace of "variables", where each string points to an another string. All strings initially point to themselves.

Instruction

Execution starts from the first command. The commands are... oh, wait... there is only one instruction. It has the following syntax:

S codesick A B C D E;

Where arguments are any strings of characters delimited by "" (but \" doesn't delimit). If the string doesn't empty, does not contain whitespace, ; or " and it's not one of codesick in out, quote marks can be ommited.

The instruction does the following:

  • Concatenate *A and *B and set *A to the result,
  • Dereference *C,
  • Is *D a substring of *A?
  • If yes, remove the first instance of *D from *A and goto *D,
  • If not, goto *E.

It can be written in pseudocode as:

*A += *B;
*C = **C;
if(*A == x + *D + y) {
 *A = x + y;
 goto *D;
} else {
 goto *E;
}

S is line string. If two instructions have the same line string, then an error is thrown. It's not obligatory; however, all instructions without line numbers are removed from the program after executing next instruction.

Extensions

Input and output

If A is out (without quote marks), B is printed into output instead and the test automatically fails.

If any argument (including line string) is in (without quote marks), it's replaced with user input before the program starts. If IP tries to goto a non-existent instruction, the program halts.

Optional dereferencing

Dereference argument is optional and can be ommited; if it is, "" is dereferenced.

Computational class

Below is sketch of Turing-completeness proof by implementing Bitwise cyclic tag:

  • Reset both "program" and "data",
  • Add "a" and input to "program",
  • Add "b" and input to "data",
  • Check if program has "a0".
  • If it has, rotate "a0", then remove "bX" from data.
  • If not, check if the program has "a1X".
  • If it has, rotate "a1X", then remove "1" from "temp1" and add "temp1" to data.
  • If not, halt.
  • Loop back.

X is placeholder for any bit, and ? is placeholder for any sequence of bits.

"a?" rotation algorithm:

  • Remove "a?" from the program,
  • Reset "temp1" and add "a?" to it,
  • Remove "a" from "temp1",
  • Add "temp1" to the program,
  • Reset "temp2", and add "a" and program to it,
  • Reset program and add "temp2" to it.

Examples

Example programs use all extensions. If value of an argument doesn't matter, * is used for it.

Hello world

codesick out "Hello, world!" * *;

Cat program

cat codesick out in * cat;

XKCD Random Number

codesick out 4 * *;

Truth machine

codesick in a 0 1;
0 codesick out 0 * halt;
1 codesick out 1 * 1;