The core RichTea runtime is, by design, incredibly useless :)
It has almost no "out of the box" functionality - Limiting itself to providing the Import function.
Import loads other RichTea modules and makes them available to the program being executed.
Therefore "out of the box", it has no notion of the most basic programming constructs, such as:
- Variable declarations
- Loops (
For,Whileetc) - Branching (
If,Switchetc)
The RichTea standard library module provides the missing functionality typically expected to be part of the core language.
Import("*" from:"modules/std")
Let(message:"I can create variables!")
Print("I can print messages and { message }")
If(true then:{
Print("...and branch...")
})All examples below assume:
Import("*" from:"modules/std")Use Let to create attributes and Set to update them.
Import("*" from:"modules/std")
Let(name:"RichTea")
Print("Hello { name }")
Set("name" to:"RichTea Language")
Print("Updated name: { name }")If supports then and else branches.
Import("*" from:"modules/std")
Let(isMorning:true)
If(isMorning then:{
Print("Good morning!")
} else:{
Print("Good evening!")
})For repeats a block a fixed number of times. The loop variable defaults to i and can be renamed with as.
Import("*" from:"modules/std")
For(5 as:"index" do:{
Print("Loop #{ index }")
})Use While for expression-based loops and Increment to mutate counters.
Import("*" from:"modules/std")
Let(counter:0)
While(counter < 3 do:{
Print("counter = { counter }")
Increment("counter")
})
Print("Done")Use ForEach to iterate over list-like input.
Import("*" from:"modules/std")
Let(items:["tea", "milk", "sugar"])
ForEach(items as:"item" do:{
Print("Ingredient: { item }")
})Map transforms each element in an input collection.
Import("*" from:"modules/std")
Let(numbers:[1, 2, 3, 4])
Let(doubled:Map(numbers mapFunction:{
// value available as i by default
i * 2
}))
Print("{ doubled }")Use Switch when selecting behavior by a single value.
Import("*" from:"modules/std")
Let(command:"status")
Switch(command :{
Case("start" then:{ Print("Starting...") })
Case("stop" then:{ Print("Stopping...") })
Case("status" then:{ Print("Running") })
Default({ Print("Unknown command") })
})Write text to a file and read it back.
Import("*" from:"modules/std")
WriteFile("Hello from RichTea" path:"./output.txt")
Let(contents:ReadFile("./output.txt"))
Print("Read: { contents }")Wrap any block with Timer to measure execution time.
Import("*" from:"modules/std")
Timer(block:{
For(1000 do:{
// work
})
})Exit with an explicit status code.
Import("*" from:"modules/std")
Print("Fatal error: missing configuration")
SystemExit(1)Use Man to inspect documentation for a standard function.
Import("*" from:"modules/std")
Man("Print")
Man("ForEach")