A scripting language for automation and system administration.
# Single quotes delimit raw string literals, not supporting escapes or
# interpolation
let cxx = 'clang++'
let build_mode = 'Debug'
let generator = 'Ninja'
# $scriptDir is set by the runtime to be the directory containing the
# currently running script (not necessarily the working directory).
#
# Double quotes delimit rich string literals, `${ expression }` is used for string
# interpolation
let build = Directory("${$scriptDir}/build")
if not build.exists() {
build.create()
}
# Within this block, set the current working directory to be our build
# directory
with ($cwd = build.path) {
# The `!` postfix operator means spawn a sub-process, using the expression
# preceding it as a command and argument list, then block until the process
# exits
[
'cmake', $scriptDir,
"-DCMAKE_CXX_COMPILER=${cxx}",
"-DCMAKE_BUILD_TYPE=${build_mode}",
'-G', generator,
]!
}
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 |