A slow scripting language.
func fib(n) {
if n <= 1 { return n }
fib(n - 1) + fib(n - 2)
}
print(fib(20))
Note that:
- This product is licensed under the BSD-3 license, meaning that there is no warranty provided for it. Use at your own risk.
- Sloth is currently in pre-alpha state, meaning it is not expected to be generally useful.
- The goal of the project is to only support Unix-like systems (currently only Linux is tested). Windows support is an explicit non-goal.
- There will not be pre-compiled builds of the interpreter until a future release. Compiling the interpreter will require an Ocaml toolchain.
User-written variables or functions must start with a lowercase letter or _.
Names starting with a capital letter are reserved for class names.
let x = 1 + 1
print(x)
First-class functions:
func makeCounter() {
let x = 0
func() {
x = x + 1
x
}
}
let counter = makeCounter()
print(counter())
print(counter())
let- variable binding keyword;let x = 1func- function declaration keyword, can be used either as a top-level declaration or an anonymous function expression;let increment = func(v) { v + 1; }for- keyword for declaring loops, can be used either in C-style loops (for let i = 0; i < MAX; i = i + 1 {}) or for-in loops over lists (for user in [user1, user2, user3] {})in- keyword for use in for-in loopsif- conditional branching keywordelse- conditional branching keyworddo- keyword for do-block expressions;let s = do {let s = "init ${getString()}"; s = "${s}${getString()}"; s}return- early return from a function blockbreak- early return from a loopcontinue- skip to the next iteration of a loopwith- bind new (dynamically-scoped) context variablestrue-Boolliteralfalse-Boolliteralnull-Nullliteral singletonnot- prefix logical NOT operator;assert(not false)
| Variable | Type | Description |
|---|---|---|
$argv |
List[String] |
The command line arguments, if any. Does not include the sloth interpreter binary |
$cwd |
String |
The current working directory |
$env |
HashMap[String]String |
The environment variables |
$script |
String |
The path to the currently running Sloth script |
$scriptDir |
String |
The path to the directory containing $script |
$stderr |
FileDescriptor |
The STDERR file descriptor |
$stdin |
FileDescriptor |
The STDIN file descriptor |
$stdout |
FileDescriptor |
The STDOUT file descriptor |