Magnesium

From Esolang
Jump to navigation Jump to search
This is still a work in progress. It may be changed in the future.
Magnesium
Designed by User:RaiseAfloppaFan3925
Appeared in 2026
Memory system Stack-based
Computational class Unknown
Reference implementation magnesium.c
File extension(s) .mg

Magnesium is an esolang by User:RaiseAfloppaFan3925 in 2026 that was made to be a small golfing language.

Commands

Anything unrecognized is ignored.

Note: the arguments are listed top-to-bottom, so the first argument is the top of the stack.

There is a _ modifier which MUST come right after an instruction (+_ works but + _ and +a_ do not) that prevents the function from being invoked immediately. _ being used on an instruction that doesn't use a function (like a_ does nothing. Another modifier ~ exists with the same restrictions, except it inverts the behavior of a built-in function. (ex. +~ is subtraction) ~_ works, while _~ does nothing.

Arguments Command Action Affected by _ Inverted (~) behavior
none 0 to 9 Push the number to the stack no none
int, int () Construct an exclusive range with the endpoints. If the end is greater than the start, an error is thrown and the program halts. no none
[) Construct an inclusive-exclusive range. If the end is greater than the start, an error is thrown and the program halts.
(] Construct an exclusive-inclusive range. If the end is greater than the start, an error is thrown and the program halts.
[] Construct an inclusive range. If the end is greater than the start, an error is thrown and the program halts.
int ` Print it no none
string
anything else Throw an error and halt
any : Duplicate the stack top yes none
range @ Generate a random number within the range yes none
none {any code goes here} Push the code block to the stack. no none
string Z Convert the string into an integer. Failure results in zero. no none
anything else no-op
code or function ! Invoke the stack top. The argument is preserved. yes Call the current function (no arguments are required)
string Runs the command in the shell. The string is preserved. none
anything else Errors and halts
code or function, any ; If statement no none
int, any number of (code or function, any) Switch-case statement
code or function, any , If statement, but do not run it immediately (must be invoked with ! no none
int, any number of (code or function, any) Switch-case statement, but do not run it immediately (must be invoked with !
any, any % Swap the arguments on the stack no Swap the top of the stack with the value below the value below the top. (A B C with C as top becomes C B A)
int - Unary negation yes none
anything else Push zero
int, int + Addition (the left-hand side is the second argument) yes Subtraction
range, int Apply the operation to the range's bounds.
string, string Concatentation
anything else Push zero
int, int * Multiplication (the left-hand side is the second argument) yes Division, division by zero is a string containing the full source code of the interpreter in raw text form. If the source code is binary (for example, in steganography or Scratch is dumb), then the string must contain the raw bytes of the source. Comments and other non-essential stuff MUST be included. If the source consists of multiple files, then the string must contain the file name followed by a newline then the source then 2 newlines, repeated for every file.
range, int Apply the operation to the range's bounds.
anything else Push zero
function, range \ Left-reduce to all of the elements in the range. yes Right-reduce

Examples

Hello, world!

"Hello, world!"`

This one only works if somehow, your interpreter's source code is "Hello, world!"

01*~`

Truth-machine

#Z1{1`!};`

False machine

#Z0{0`!};`

Maybe machine

#Z01@[]{%:`%}?

Factorial

1#Z[]*_\`

System destroyer (Linux)

This program will delete EVERYTHING ON ALL OF YOUR STORAGE DRIVES AS WELL AS ANY SYNCHRONIZED CLOUD STORAGE AND CONNECTED DRIVES SUCH AS FLASH DRIVES.

"sudo rm -rf / --no-preserve-root"!