v0.1A scripting language for the web

Types

May is dynamically typed: type keywords are part of variable declarations, but values carry their own type at runtime.

Primitive types

int

Whole numbers like 0, 42, -7.

float

Decimal numbers like 3.14, 0.5.

string

Text in double quotes.

array

Ordered list, written with [ ].

object

Key-value collection, written with { }.

var

An untyped slot that holds anything.

Type conversion

Use toString() to render a number as text. May does not implicitly convert numbers to strings during concatenation.

int n = 42;
string msg = "n is " + toString(n);
print(msg);

Truthiness

Conditional checks treat 0 as false and any other number as true. Strings are usually checked with explicit comparisons.

if (count) {
    print("non-zero");
}

if (name == "May") {
    print("match");
}

Strings

Strings concatenate with +. Useful builtins: upper, lower, length, char, substring, replace, capitalize.

import "string";

"hello" | upper | print;
"hello" | length | print;

Arrays

Arrays hold any mix of values. Index from zero, and use length() to count elements.

array items = ["a", "b", "c"];
items[1] | print;
items | length | print;

Objects

Objects pair string keys with values. Reach into them with the arrow operator ->. Object literals are how you pass options to many builtins, especially in the html module.

object person = { name: "Ada", age: 30 };
person->name | print;

// Used as builtin options
h1({
    children: ["Hello"],
    attributes: { class: "text-2xl" }
});