Quick Start
Write your first May program in under a minute. By the end of this page you will have run a script, used the pipe operator, and served a web page.
Hello world
Create a file called hello.may:
import "io";
print("Hello world!");
colprint("Hello world in red!", "red");Run it:
may hello.mayVariables and types
May has a small set of types you declare with keywords:
int count = 0;
string name = "May";
float pi = 3.14;
object user = { name: "Ada", age: 30 };
array scores = [88, 92, 75];
var anything = 42;The pipe operator
May has a Unix-style pipe operator that feeds the value on the left into the function on the right. It makes data transformations read top-to-bottom, left-to-right.
import "io";
import "string";
"hello world" | upper | print;Equivalent to print(upper("hello world")) but easier to extend.
Functions
Declare functions by writing a return type, a name, parameters, and a body:
int square(int n) {
return n * n;
}
square(5) | print;Your first server
May has an HTTP server and an HTML builder built in. Here is a complete web app:
import "io";
import "http";
import "html";
string home() {
return html({
children: [
body({
children: [
h1({ children: ["Welcome to May"] }),
p({ children: ["This page was rendered by a 20 line script."] })
]
})
]
});
}
int server = create_server(8080);
print("Listening on http://localhost:8080");
while (1) {
int client = accept_client(server);
object req = read_request(client);
send_html(client, router(req, { "/": home() }));
}Run it with may server.may and open http://localhost:8080.
Where next?
Read the Syntax page for a full tour of the language, or browse the Standard Library to see every builtin available.