๐Ÿ“˜ W++ Syntax Guide

Because sanity is optional.

๐Ÿ”ค Variables

let x = 42;
let name = "Sloth";

๐Ÿ”’ Constants

Use const to declare a variable that cannot be reassigned.

const PI = 3.14159;
const greeting = "hello";

PI = 3; // โŒ Error: Cannot assign to constant

๐Ÿง  Lambdas

let add = a => b => a + b;
let result = add(2)(3);

โšก Async Lambdas

let getData = async url => {
  let res = await http.get(url);
  return res.body;
};

๐Ÿงฑ Control Flow

if x > 10 {
  print "Big";
} else {
  print "Small";
}

while x > 0 {
  print x;
  x = x - 1;
}

for let i = 0; i < 3; i = i + 1 {
  print i;
}

switch x {
  case 1 {
    print "one";
  }
  case 2 {
    print "two";
  }
  default {
    print "many";
  }
}

๐Ÿ›  Operators

๐Ÿงฌ Entities & OOPSIE OOP

entity Animal {
  speak => {
    print "rawr";
  }
}

entity Dog inherits Animal {
  speak => {
    print "bark";
  }
}

alters Animal with Dog {
  speak => {
    print "reverse bark";
  }
}

let d = new(Dog);
d.speak();

Keywords

๐Ÿ•ธ Built-in APIs

let res = await http.get("https://api.example.com");

let res = await http.post("https://api", "body", {
  "Authorization": "Bearer sloth-token"
});

let obj = await json.parse("{ \"key\": \"value\" }");
let text = await json.stringify(obj);

๐Ÿงช Errors & Exceptions

try {
  throw "oh no!";
} catch e {
  print "Error caught!";
}

๐Ÿงต Other Things