COD

From Esolang
Jump to navigation Jump to search

COD is a two-dimensional esolang by User:PythonshellDebugwindow where code are the instruction pointers. It has nothing to do with Deadfish.

Overview

Programs in COD are two-dimensional. They're made up of "ponds", which must be fully enclosed by waves (except for the ... and --- commands). Instruction pointers ("cods") move around ("swim") in the ponds, guided by "waves", which cods can't move through. If a cod encounters a branch in its pond, e.g. it can go multiple different ways, it will choose a random branch, but will keep going the same way. If a cod reaches a dead end, it will turn around; if it's completely blocked in, the program will loop forever as a result. Programs can have multiple individual ponds in them, but each one must have access to either the left, right, or both sides of the program.

Syntax

The most basic ponds are made only of waves (~ tilde characters) and water (spaces), like this one, which is basically just a rectangle:

~~~
~ ~
~~~

Cods can move freely through everything but waves and other cods, meaning the commands don't affect cods' motion (except for _).

> represents a cod. Without any cods, a program will instantly terminate (and if at any time during execution a program has no cods, it will terminate). For example, the aforementioned rectangle has no cods and would terminate instantly. This program, however, would loop forever, as its cod will stay there forever):

~~~
~>~
~~~

Cod values

Each cod has a value, an unbounded signed integer that starts at zero.

Commands

Where "the cod" is any cod that passes over a command:

Command Meaning
+ Duplicate the cod (if there are two branches, one of them will continue and one of them will go back; if there are three branches, they will each go different forward branches; more, then they will each go different, but otherwise random, ways)
- Remove the cod
) Increment the cod's value
( Decrement the cod's value
< Remove the cod if its value is equal to zero
_ If the cod is going up when it hits this command, then send it back down if its value is nonzero; otherwise, do nothing

Edge commands

The --- (three dashes) command (output the cod's value, then remove the cod) must be touching either the left or right side of the program, without any waves or other characters in between, otherwise it will count as three - commands. This command is executed when a cod encounters one of the side dashes on this command. This command must go left-to-right, e.g. the dashes must all be right beside each other.

Similarly, the ... (three periods) command (input a number to the cod's value from STDIN) must be touching either the top or bottom edge of the program, without any waves or other characters in between, otherwise it will be completely ignored. This command is executed when a cod encounters any of the periods in this command. This command must go top-to-bottom, e.g. the periods must all be right on top of another.

Examples

Infinite loop

Basic one:

~~~
~>~
~~~

More advanced one:

~~~~~
~>  ~
~ ~ ~
~   ~
~~~~~

Infinite numeric cat

 ~.~
~~.~~~~
~>.+---
~ ~ ~~~
~   ~
~~~~~

Truth-machine

 ~.~
~~.~~~~
~>.+---
~~~<~~~
  ~_~~~
  ~+---
  ~ ~~~
  ~~~

Raise an error (takes 3 inputs first)

 ~.~
 ~.~
~~.~
~> ~
~~~~

The program errors because the cod goes through the input command and into nothing.