Quickstart
Write, check and run your first PickleScript program.
This page walks through a complete first program. It assumes you have installed the CLI already: see Installing PickleScript if you have not.
Write a file
Create main.pkl next to the pickle-cli binary, or anywhere you like:
module hello
fn main() {
let recipient = "world"
let count = 3
println("Hello, {recipient}!")
println("We will repeat that {count} times.")
var i = 0
while (i < count) {
println(" {i + 1}. hello again")
i = i + 1
}
}
A few things to notice:
printwrites its arguments with no separator and no trailing newline.printlndoes the same but adds a newline. Callprintln("")when you need a blank line.{recipient}is interpolation. The expression inside the braces is evaluated and inserted, soprintln(" {i + 1}. hello again")works.letcreates an immutable binding;varcreates a mutable one. Rebinding aletis a compile error.- A module is a sequence of declarations. Statements may only appear inside a function body, never at the top level.
Check it
pickle-cli check main.pkl
check parses, resolves and type-checks without executing anything, which makes
it the fastest way to catch mistakes. It exits non-zero on error.
Run it
pickle-cli run main.pkl
Hello, world!
We will repeat that 3 times.
1. hello again
2. hello again
3. hello again
run compiles the program to machine code and executes it, so there is no
separate build step.
Pass arguments
Extra arguments after -- are surfaced to the program by args():
pickle-cli run main.pkl -- alpha beta
fn main() {
for (a in args()) {
println("arg: {a}")
}
}
Add a test
Tests live in the same file or in a separate test file beside it. A test fn is
discovered by the test runner:
fn fib(n: int) -> int {
if (n < 2) {
return n
}
return fib(n - 1) + fib(n - 2)
}
test fn fib_is_correct() {
expect(fib(10)).toBe(55)
expect(fib(0)).toBe(0)
}
pickle-cli test main.pkl
running 1 test(s) from main.pkl
test fib_is_correct ... ok
test result: 1 passed; 0 failed
Writing and running tests covers the full assertion vocabulary and test grouping.
Next steps
- Running programs: checking, running, and testing a program.
- Language overview: how the pieces fit together.
- Builtin functions: what is available without importing.
