Advanced Topics
Once you’re comfortable with the basics, you can explore more advanced features of StellarTrails. Some of these may be experimental or in early stages.
Closures
Functions can return other functions, capturing variables from their environment:
fn make_adder(x: Int) {
return fn(y) => x + y
}
let add5 = make_adder(5)
print(add5(10)) # Output: 15
Recursion
A function can call itself:
fn factorial(n: Int): Int {
if n <= 1 {
return 1
}
return n * factorial(n-1)
}
print(factorial(5)) # Output: 120
Enums
enum Color {
RED,
GREEN,
BLUE
}
let c = Color.RED
Next: Running and Testing Code