Skip to content

Basic Tutorial

Luis Albizo edited this page Aug 27, 2018 · 30 revisions

Introduction

Variables

A variable name in wardscript can contain letters a-z, A-Z , numbers: 0-9, and a few special symbols: _ $ '.

a := 12;
b := a, c := b;

Data Types

There is only 4 data types in wardscript:

  • Byte
  • Nil
  • Node
  • Function

Byte

A byte is an unsigned integer lesser than 256

b1 := 0,
b2 := 255;

Nil

The Nil datatype represents the absence of value and is useful in data-structure implementation.

root := nil;

Note: nil is not a keyword, it's only a variable predefined in all programs

Node

In dynamic data structures, a node is a record that contains a data of interest and at least one pointer to reference to another node.

A node in wardscript is similar to a structure in c, but dynamically typed as in python or lua (dictionary and table), it differs from these by being immutable; which means that once a node is created, it can not have new members or eliminate those that already exist, only modify its content.

To create a node write a list of assignments (members) between curly brackets { }.

root := {
    data := 0,
    next := nil
};

To modify a member value

root.data := 1;

Function

Functions in wardscript are first-class values (wikipedia). To declare a function we must assign it to a variable. The syntax to declare a function is the following:

func arg1, arg2, arg3: result:
    ? Block of code ?
end

More examples:

f := func x, y: x:
    x := x + y;
end;

f2 := func x, y: nil:
    if x > y then
        present(x);
    else
        if y > x then
            present(y);
        else
            present(x, y);
        end
    end
end,

f2' := func x, y: nil:
    if x > y then
        present(x);
        exit;
    end

    if y > x then
        present(y);
        exit;
    end

    if x == y then
        present(x, y);
        exit;
    end;
end;

hello := func : nil:
    ? A function does not necessarily have to have arguments. ?
    print("Hello World!",10);
end;

Notes

  • The argument list may be empty so the argument list won't take any argument at moment of call.
  • The 'return variable' may or may not be declared inside the function body, but it has to exist in the scope at the momento of call. (an example is function f2)
  • The 'exit' keyword it's like a return in the sense it breaks the flow of the function and the function return whatever the return variable has in that moment. (example of use in f2')

Control Flow

If clauses

Loops

A loop is equivalent to a while True or a while (1)

Clone this wiki locally