Cood

From Esolang
Jump to navigation Jump to search

Cood (code and food) is an interpreted stack-based esoteric programming language based on the phrases you usually will say in a restaurant.

There are three known official interpreters available, coded in AutoIt, PHP and Javascript.

Documentation

Every script starts with a "Hey, waiter!", although it is not mandatory.

The programmer has access to 65,535 data cells, starting in pointer 32,767.

Functions

Command Function
Hey, waiter! Starts the script.
The bill, please. Ends the script.
I want this. Increases a byte at the current data pointer.
I don't want this. Decreases a byte at the current data pointer.
What do you have for dessert? Increments the data pointer (points to the next cell to the right).
What do you have for tidbit? Decrements the data pointer (points to the next cell to the left).
May I ask something? Reads STDIN (user input).
I'm hungry. Reads the current data pointer value, and adds a trailing line break.
I'm very hungry. Reads the current data pointer, without trailing line break.
How much is it? Reads the current data pointer as decimal value rather than ASCII.
I hate this. Zeroes the current data pointer.
I want [number] of this. Puts [number] value at the current data pointer.
More [number] of this. Adds [number] value to the current data pointer.
Less [number] of this. Decreases [number] value at the current data pointer.
What do you suggest? Starts a loop. Read below about loops.
Nothing more? Ends a loop. Read below about loops.
Know a joke? [comment] Way to comment out your code.


All punctiation (commas, periods) is non-mandatory. It is also possible to indent the code with spaces or tabs. Also, the code will understand if the programmer replaces "I'm" with "I am".

Loops

In Cood, loops are made using "What do you suggest?" and "Nothing more?". All the code between these tags is repeated until the current pointer (it must be the current pointer at the time of "Nothing more?" call) is zero. Example:

Hey, waiter!
I want 10 of this.
What do you suggest?
Know a joke? This line will run ten times.
I don't want this.
Nothing more?

It's worth to remember to always decrease the pointer value (or increase if the code is dealing with negative values), as the loop doesn't decrease it automatically. This is done using "I don't want this.". Also, the code above won't display anything.

Debugging

Cood also includes a simple line-by-line debugger, accessible by adding "--debug" as second parameter when running the script.

interpreter "My awesome script.cood" --debug

Examples

Hello World

This is a simple way to write HelloWorld! by using an ASCII table.

Hey, waiter!
I want 72 of this.
I'm very hungry.
I want 101 of this.
I'm very hungry.
I want 108 of this.
I'm very hungry.
I'm very hungry.
I want 111 of this.
I'm very hungry.
I want 32 of this.
I'm very hungry.
I want 87 of this.
I'm very hungry.
I want 111 of this.
I'm very hungry.
I want 114 of this.
I'm very hungry.
I want 108 of this.
I'm very hungry.
I want 100 of this.
I'm very hungry.
I want 33 of this.
I'm hungry.

Countdown

As the decimal 0 (zero) value is not the char 0 (zero), and the numbers start at the position 48 on the ASCII char, it is necessary to work with two data cells: the first one, with value 10, will control the loop. The second one, with the value 57 (chr '9'), will be displayed. Remember it is necessary to decrease both the cells' values and move to the right one before the loop ends.

Hey waiter!
Know a joke? This is a comment
I want 10 of this.
What do you have for dessert?
I want 57 of this.
What do you have for tidbit?
What do you suggest?
What do you have for dessert?
I'm hungry.
I don't want this.
What do you have for tidbit?
I don't want this.
Nothing more?

Another example of loop asking for user input.

Hey waiter!
Know a joke? This is a comment
May I ask something?
What do you suggest?
What do you have for dessert?
I want this.
What do you have for dessert?
I want this.
What do you have for tidbit?
What do you have for tidbit?
I don't want this.
Nothing more?
What do you have for dessert?
More 48 of this.
What do you have for dessert?
What do you suggest?
What do you have for tidbit?
I'm hungry.
I don't want this.
What do you have for dessert?
I don't want this.
Nothing more?

Sum

The script below will store the user's numbers in two different cells, then loop one over another, decreasing one of them and increasing the other. For example, if the user inputs the numbers "2" and "3", it will have two stacks:

[2] [3]

When the loop is running:

[2] [3] (initial state)

[1] [4]

[0] [5]

The result is showed on the second stack, and it will be showed as decimal.

Here is the code:

Hey, waiter!
Know a joke? This is the sum calculator.
May I ask something?
What do you have for dessert?
May I ask something?
What do you suggest?
What do you have for tidbit?
I want this.
What do you have for dessert?
I don't want this.
Nothing more?
What do you have for tidbit?
How much is it?

External resources