The language isn’t really all that powerful (I wrote it for a school assignment). We have variables, which we can declare with either var
, for normal variables or var!
for constants and there is shorthand declaration with the :=
operator (which doesn’t require a var keyword). We won’t deal with datatypes but rather let JavaScript handle that.
Littl also has C-style comparison and mathematical operators. Values can be returned with the return
keyword.
Declared like: for variable in array
Declared like: for variableDeclaration; condition; operation
Declared like: if condition
Optional: or if
Optional: else
a := 5
if a < 10 {
console.log("a is smaller than 10")
}
or if a > 21 {
console.log("a is bigger than 21")
}
else{
console.log("a is bigger than 10")
}
These statements have C-like blocks (curly brackets).
Since Littl transpiles to JavaScript, one can use JavaScript functions like console.log
.
A recursive fibonacci sequence would look like so:
fib n {
if n is 0 or n is 1 {
return n
}
return fib(n-1) + fib(n-2)
}
x := fib(12)
console.log(x)
Since Littl is part functional, every scope, be it if
, for
or a function scope, can be put into a variable or returned.
count := for i := 0; i not 10; i = i + 1 {
console.log(i)
}
count()
var! two = 2
twoSmallerThanThree := if two < 3 {
return true
}
twoSmallerThanThree()
curryAddition := anonymous x {
return anonymous y {
return x + y
}
}
add3 := curryAddition(3)
console.log(add3(2))