ismael-miguel / mariogolf

Mario Golf - Golfing programming language based on pipes. Run out of pipes and die.
MIT License
2 stars 0 forks source link

Mario Golf

Golf programming language based on pipes.

Run out of pipes and die.


About Mario

Mario is a stack-based language which pipes information to multiple commands.

Mario has 2 automatic registers, being R the returned value of some operation/function and I the register of a loop.
Also, the register Z contains the last returned value from a block, while L contains the length of the stack.

Each command receives it and processes it individually.

Syntax

All Mario programs must start with an identifier and a pipe.

Example (shortest valid Mario programs):

M|O
P|Q

Valid identifiers and effects:

The order matters!
BY and YB work differently.
BY receives input and turns into negative numbers, then places the quine.
YB places the quine and then it is turned into negative numbers.

Comments

Comments must be in a line on its own. They can start with any character except the characters.

Example:

Mario can make tiny `cat` programs:
M|O
# isn't required to be the first character, and may be nowhere!

Only the first valid sequence of identifiers with a pipe will be ran:

Mario can make more tiny `cat` programs:
M|O
Y|;|O <-- won't run!

Return sequences

You are required to use a return sequence.

The return sequence is the last character in the pipeline.
In the examples gived in the point above, it is the last character.

Here are them all (full sequence with |):

Where not specified, it returns what is in the stack as a string.

Every program is itself a function.

Literals

There are a few ways to write literal values:

Commands

Arithmetic

It is possible to do math with Mario.

Examples:

M|+c|O

Which outputs the sum of the first character and c.

List of arithmetic symbols:

Stack operations

You can also manipulate the stack directly.

Allowed commands:

Comparisons

Comparing values is hard.

But can be done!

Symbols:

Example:

M|>:<çC|O

Reads the first character into the register R, destroys the stack and pushes the result of comparing it with C into the stack, displaying it.

If a condition is verified, is produces 1, otherwise 0.

Blocks and loops

There are a few loops one can do.

For loop (|#n)

The for loop loops a number until it reaches 0, and will be stored in the register I.

Example:

Y||#9<|N

Receives no output, disables negative numbers and output from 9 to 0.

For loop (|$n)

Exactly the same as above, but it goes towards n instead of towards 0 (as with |#n).

Foreach (|&)

Goes through every element in the stack, storing it in the register.

Example:

Y||#F<|&*5|N

Outputs the result of multiplying all numbers from 0 to 10.

Blocks

Code blocks are contained within {} and may return values

Example:

M|>|${\3+5}<+1|O

Reads the input, takes the first character, and loops from 0 to (Z % 3)+5 summing 1 in each iteration and pushing it into the stack.

Conditional execution

This works as an if on other languages.

You use |% and then you use 1 pipe or a block.

An else is |@.

Example:

M||&{|%><+5|@{|%=5+1|@.}}|O

If the current value is 0, sums 5.
If it is 5, then add 1, otherwise destroy the value.

Same code, in PHP (badly golfed):

foreach($z=&$_POST as$k=>$v)if($v){if($v==5)$v++;else unset($z[$k]);}else$v=5;print_r($z);return$r;

Variables

Variables are named registers.

To declare a variable, use a pipe and then a name, which can be the range a-z.

Use = to give it a value. If no value is specified, it will receive the value on the register R.

All the variables are global.

Example:

M||&|z={+5}<|z|O

Receives the input, sums 5 to everything in the stack and outputs it.

Other registers:

Tricks

You can do very quick ROT13 quines:

K|1

You can process numbers as large as you wish:

Y|<9^99|O

Or sum characters:

M||&<+'~|O