๐ค 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
+
,-
,*
,/
==
,!=
,>
,<
,>=
,<=
&&
,||
,!
??
โ null coalescing
๐งฌ 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
entity
โ defines an OOP sloth-structurealters
โ reversely override methods of ancestorsdisown
โ opt-out of parental inheritanceme
โ reference to current instanceancestor.method()
โ call original method before it was altered
๐ธ 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
typeof(String)
โ returns .NET type infoawait
โ used with async calls and tasksnull
โ the void in your soulimport "file.wpp"
โ imports another W++ file