A tiny and simple code-golf language, written in Clojure.
Anything inside single quotes are pushed to a stack. Every character not inside single quotes is an operator. Operators are basically functions for Golfd. They take the entire stack as argument, and modify the stack as much as they want. Here’s how a hello world program is written, and how it works:
The code:
'Hello, world!'p
Explanation:
So, let’s start with the Hello, world!
part. As I mentioned before,
anything in single quotes is pushed to the stack. The stack is just an
array, so the stack now looks like ["Hello, world!"]
. The next part here
is p
. p
is the print operator. It takes the last item on the stack,
prints it and removes it from the stack. So we get Hello, world!
printed
after the p
operator and stack is now empty ([]
).
One thing to note about the language is that each line has its own stack. This means if you want to clear the stack you can just move to a new line.
Here’s a list of operators, until there is a proper wiki page.
Operator | Description |
+ | Adds last 2 items in stack |
p | Prints last item in stack |
P | Prints all items in stack |
Ṗ | Prints all items in stack joined by spaces |
. | Takes user input |
- | Subtracts last 2 items in stack |
* | Multiplies last 2 items in stack |
/ | Divides last 2 items in stack |
s | Sorts all items in stack (calls clojure.core/sort) |
S | Sorts all items in stack after converting them to numbers |
i | Increments last item in stack |
d | Decrements last item in stack |
I | Increments all items in stack |
D | Decrements all items in stack |
~ | Splits the last item in stack by spaces, and adds it to the stack |
> | Moves item at index to top of the stack, the index is the last item of the stack |