Skip to content

Latest commit

 

History

History
263 lines (198 loc) · 4.34 KB

README.md

File metadata and controls

263 lines (198 loc) · 4.34 KB

Wuzh language

Release version badge

func HelloWorld() {
    PrintLine("Hello, world!");
}

HelloWorld();

Download exe

Contents

Files

wuzh.exe - interpreter (link)

*.wuzh - file extensions

Examples

Syntax

Declaration

x := 4;
const PI := 3.14;

Assignment

x = 21 * 2;

Basic types

# Unit
u := unit;

# Integer
x := 42;                
l := 1_000_000;         

# Double
y := 3.14;              

# String
z := "Hello";           

# Boolean
a := true;              

# Array
b := [1, "two", 3.14];  
range := [1..10];       

# Dictionary
d := {                  
    "name": "Vlad", 
    "age": 19
};

Type hinting

String str := "string";
Any str2 := "string2"; # str2 type is String

func Function(Int a, Int b) -> Int {
    return a * b;
}

func Function2(Any a, Any b) -> Any {
    return a + b;
}

func Function3(a, b) {
    return a / b;
}

Indexing

arr := [1, 2, 3];
x := arr[0];        # x = 1

str := "Hello";
c := str[0];        # c = "H"

dict := {                  
    "name": "Vlad", 
    "age": 19
};
d := dict["name"];   # d = "Vlad"

# Index assignment
arr[0] = 3;
str[0] = "B";
dict["name"] = "Bob";
dict["height"] = "180cm";

If statement

if (x > 30) {
    PrintLine("x is greater than 30");
} else {
    PrintLine("x is less than or equal to 30");
}

While loop

while (x > 0) {
    PrintLine(x);
    x = x - 1;
}

For loop

for (i := 0, i < 5, i = i + 1) {
    PrintLine(i);
}

For(each) loop

arr := [1, 2, 3, 4, 5];
for (item in arr) {
    PrintLine(item);
}

# Range from 1 to 10
for (i in [1..10]) {
    PrintLine(i);
}

str := "Hello, world!";
for (c in str) {
    PrintLine(c);
}

Function declaration

func add(a, b) {
    return a + b;
}

func mult(Int a, Int b) -> Int {
    return a * b;
}

func factorial(n)
{
    if(n == 0)
    {
        return 1;
    }
    else
    {
        return n * factorial(n - 1);
    }
}

# Return type is Unit
func printName(name) {
    PrintLine(name);
}

Function call

result := add(3, 4);

Comparison operators

# > < >= <= == !=

if (x > y) {
    PrintLine("x is greater than y");
}

if (a == b) {
    PrintLine("a is equal to b");
}

Operations

# Operations on numbers: + - * / // %
number := (1 + 2 * 3) / 2;              # number = 3.5

# Operations on arrays: +
arrConcat := [1, 2] + [3, 4];           # arrConcat = [1, 2, 3, 4]

# String operations: + *

strConcat := "Hello" + " " + "world!";  # strConcat = "Hello world!"
strRepeat := "Hello" * 3;               # strRepeat = "HelloHelloHello"

Basic types

The Wuzh language supports the following types:

  • Unit: Empty type, void analog
  • Integer
  • Double
  • String
  • Boolean
  • Array
  • Dictionary
  • Any: Auto-detects type in variables, means any type in function parameters and return type

Standard library

List of functions in the standard library: StdLib/