Mutzerium

From Esolang
Jump to navigation Jump to search

Mutzerium is designed by PSTF in OTL Universe, which is inspired from SLet 3.0(Currently, SLet is using 4.0 version).

In PsiLine Universe, it is designed by Yang Jiong.

Language Overview

Mutzerium is Turing-Complete, almost-high-level, and uses easy syntax.

To Do

  1. Implement it without any standard library
  2. Implement standard libraries
  3. Make Wolfram-110 in it
  4. Make Conway's Game of Life in it
  5. Implement Brainfuck by it
  6. Make a Universal Turing Machine in it

Basic Syntax Concept

Comments

Code between ` and ` are comment.

Data Types

In this programming language, there are 6 data types.

Number(num): Often shows as an fraction. Size is unlimited. Divide by 0 gets an undefined behaviour(NaN) if divident is 0, and gets infinity if divident is non-zero.
  Fraction: The format of the fraction is A/B.
  Integer: A fraction with a denominator of 1 can be directly expressed as an integer.
  Float number: It can also be represented as a number in the form of a floating-point number.
  Complex: Format is a+bi. 1i shouldn't express with i.
String(str): Quoted by quotation mark. Sextuple is also work, but it is document.
Boolean(bool): True or False.
Array: Most important in Mutzerium. Quoted by bracket, and seperate with comma. It won't automatically sort.
  Since pair is removed, we uses something like [key: value, key: value] to represent a dictionary.
Null: A null variable.
Tuple: "Unchangable array", can't simply modify an element in it. Use (x, ) to make a tuple with only one element.

0, "", [], (, ) will be false when convert to boolean. NaN returns "", Infinity returns 99 bottles of beer.

Flow Control

for          | For every object B in iterative container A, do the code C.
while        | While boolean(condition) A is True, do the code B.
repeat       | Do the code B for A times.
lambda       | Start definition of non-argument lambda function. End with "end".
function     | Start definition of function, with name A and code B, and argument list.
call         | Call a lambda function.
return       | Returns a specified value.
break        | Break out current loop immediately.
continue     | Skip this round of current loop.
label        | Defines a label. End with "all".
exit         | Exit program immediately.
halt         | Halt until user's keystroke.
wait         | Halt for A milliseconds.
goodbye      | Exit the programming environment.
pass         | Exit the programming environment.

I/O

input        | Return a string that you've inputted.
evinput      | Return the result of the expression you've inputted.
getchar      | Return the ASCII of the character you've inputted.
print        | Print the value of object A. 
decprint     | Print a fraction as real number to B'th digit to point.
putchar      | Print the character with corresponding code point. If code point is not an integer then round as usual.

Data structures and Calculations

opposite     | Not boolean A. Negate number A. Reverse string/array A.
swap         | Swap the two pole objects in tuple A. If A is a number, return its reciprocal. For example, "swap 0.5" will return 2.
former       | First object of tuple A. Numerator of number A.
latter       | Last object of tuple A. Denominator of number A.
append       | Append A to the tail of an array.
insert       | Insert A to the specified position of an array.
pop          | Pop the specified position of an array and store into A. If store into null, then means discard it.
exist        | True if object A is a subset of object B.
first        | Returns the smallest item in an array. null<bool<num<str<pair<array.
add          | Does addition between numbers. Also can use +. Infix.
or           | Does OR between booleans. Also can use |. Infix.
multiply     | Does multiplication between numbers. Also can use *. Infix.
and          | Does AND between booleans. Also can use &. Infix.
intersect    | Does intersection between arrays. Infix.
union        | Does union between arrays. Infix.
divide       | Does division between numbers. Also can use /. Infix.
floordiv     | Does floor division between numbers. Also can use //. Infix.
modulo       | Does modulo between numbers. Also can use %. Infix.
minus        | Does subtraction between numbers. Also can use -. Infix.
power        | Does exponent between numbers. Also can use ^. Infix.
root         | Does root between numbers. Infix. "4 root 2" should return 4^(1/2).
log          | Does logarithm between numbers. Prefix. 
             | The first parameter is the base, and another parameter is the value to be taken as a logarithm.
range        | Python "range(A,B+1,C)". Returns an array.
slice        | Python "array[A:B]". Returns an array.
bor          | Does OR between numbers. Also can use ||. Infix.
band         | Does AND between numbers. Also can use &&. Infix.
bxor         | Does XOR between numbers. Also can use ^^. Infix.
filtrate     | For every object in array A, store it in variable named B, if C is false, throw away the item.
size         | The size of array A. The length of string A.
var          | Define a variable called A, with type B and value C.
let          | Assign a value to variable A. Assign with type will change its type.
index        | Returns the corresponding indexed elements in an array. Indexing starts at 0 and works like Python.
round        | Rounds a number as usual.
ceiling      | Rounds a number away from 0.
floor        | Rounds a number towards 0.
rand         | Generate a random 4-digit float number between 0 and 1.
randrange    | Generate a random integer between a and b.
uniform      | Generate a random float number between a and b.
choice       | Select an element at random from an array.
time         | Built-in constant, represented by UNIX timestamps.
datetime     | Convert the argument (timestamp) to the corresponding time. Returns a string.
shuffle      | Scramble an array randomly.
sort         | Sort an array.
push         | Push the argument to the stack. Stack can be treated as array, 
             | and use "stack" to represent it.
pop          | Pop stacktop from stack and store into argument. 
             | If no specified argument, discard it.
stacktop     | Stack top.
stack2nd     | 2nd to top element of stack.
import       | Import specified libraries.
from         | Only from the specified libraries import things you want. Format: from lib import module
             | If module name is all, then import all modules.

Built-in Constants

True, False, NULL, NaN, infinity, M_PI, M_TAU, M_E, M_PHI

STL

Mutzerium/STL

Examples

Hello, world!

for "Hello, world!" i {put-char i}

A shorter version

print "Hello, world!"

Greatest Common Divisor

function gcd [x, y] {return x/former x/y} print gcd(input, input)

Here's the original SLet 4 code:#x,#y,./x<*x$y

Least Common Multiple

function gcd [x, y] {return x/former x/y} function lcm [x, y] {return x*y/gcd(x, y)} print lcm(input, input)

Circle area

print (M_PI * (input ^ 2))

Mid-Autumn Festival Dice Game

repeat 6 {push randrange 1 6} opposite stack while stack {print stacktop putchar 32 pop}

99 bottles of beer

var a string infinity print a

Categories and References