Reference

Command line

CommandWhat it does
cresset run <file.crs>Check, then run a program. By default only print is allowed.
cresset check <file.crs>Check permissions and types, and list each function's needs. Runs nothing. --json prints every problem as data (line, message, hint, file).
cresset install <name[@version]>Copy a package from a registry into cresset_packages/ (--dir to change). Shows the permissions it needs first. --registry <folder or web address> (or set CRESSET_REGISTRY), --force to replace a different version. See Package registry.
cresset publish <file.crs>Add a package to a registry folder: --name, --version, --registry. Versions never change once published.
cresset search [text]List the packages in a registry.
cresset lock <file.crs>Pin every imported package by SHA-256 in cresset.lock. Afterwards a changed or new package is refused. --no-lock (on run and check) ignores the lock. See Packages.
cresset outline <file.crs>List the functions, records, enums and imports (with signatures and doc comments) as JSON, for editors.
cresset fmt <file.crs>Print the file in the standard style. --write rewrites it; --check exits with 1 if it would change.
cresset redact <file or -> ...Swap secrets for placeholders. See Redaction.
cresset restore <file or -> --map key.jsonPut the real values back.
cresset --versionPrint the version.

Options for run:

OptionMeaning
--allow a,bGrant effects: input, env, read, write, network, time, random (and print, which is on by default)
--allow-allGrant every effect
--record file.jsonSave every non-repeatable effect so the run can be replayed
--replay file.jsonRun again using a recording
-- word wordEverything after a bare -- goes to the program, which reads it with args() (needs env).
--max-steps NStop with an error after N evaluation steps. A safety net against a loop that never ends.

Run it as node cresset.js ..., or with the wrapper scripts cresset and cr on Windows.

Keywords

fn, use, record, enum, match, needs, requires, ensures, if, elif, else, for, while, in, return, break, continue, and, or, not, true, false, none

from and allow have a special meaning only on a use line.

Operators

From tightest to loosest:

OperatorsMeaning
x.y, x(...), x[i], x?Field or method, call, index, pass a failure up
-xNegate
* / %Multiply (or repeat text), divide, remainder
+ -Add (numbers, text, lists), subtract
== != < <= > >= in not inCompare, membership
notLogical not
andLogical and
orLogical or

Assignment forms: =, +=, -=, *=, /=.

Built-in functions

FunctionNeedsReturns
len(x)Length of text, a list or a map
str(x)The text form of any value
type(x)The name of the value's type
abs(n), floor(n), round(n)A number
min(...), max(...)The smallest or largest number (list or separate arguments)
range(n), range(a, b)A list of numbers, ending before n / b
ok(x), err(x)A result
to_int(text), to_float(text)A result holding the number
assert(cond, message)Stops the program if cond is false
assert_eq(actual, expected, message)Stops the program if the two values are not equal, saying what each was
print(...)printPrints its arguments separated by spaces
input(prompt)inputA result holding the line the user typed, or err when there is no more input. The prompt is optional.
read(path)readA result holding the file's text
write(path, text)writeA result
fetch(url)networkA result holding the response text of an HTTP or HTTPS GET, or err("HTTP 404 Not Found") and similar. Times out after 10 seconds; responses over 5 MB are refused. Not available in the browser playground.
post(url, text)networkThe same, sending text as the request body
sleep(seconds)timePauses. A replay skips the wait.
shuffle(list)randomA new list with the items in random order
choice(list)randomOne random item (the list must not be empty)
args()envThe words after -- on the command line, as a list of text
env(name)envA result holding an environment variable's value
exists(path)readtrue or false
list_dir(path)readA result holding the sorted names in a folder
append(path, text)writeA result: adds text to the end of a file (creating it if needed)
delete_file(path)writeA result
make_dir(path)writeA result: creates the folder and any missing parents
now()timeSeconds since 1970
random()randomA number from 0 up to (not including) 1
randint(a, b)randomA whole number from a to b, both included
sqrt(n), pow(a, b), ceil(n)Math. sqrt of a negative number is an error
fixed(n, digits)The number as text with that many decimal places: fixed(3.14159, 2) is "3.14"
json_parse(text)A result holding maps, lists, numbers, text, booleans and none
log(n), log10(n), sin(n), cos(n), tan(n), atan2(y, x), pi()Math (angles are in radians)
rng(seed)A seeded random generator (number or text seed). Pure: the same seed always gives the same numbers. See Simulations.
clamp(n, low, high)n, but no smaller than low and no larger than high
iso_time(seconds)Seconds since 1970 as text like "2026-12-06T10:00:00.000Z"
parse_time(text)A result holding seconds since 1970
regex_test(pattern, text)true if the pattern matches anywhere in the text
regex_find(pattern, text)A list of every match
regex_replace(pattern, text, with)A copy with every match replaced
json_stringify(x), json_stringify(x, indent)The value as JSON text. Records become objects; enums become {"variant": ...}

In double-quoted text, { starts an insertion, so a literal brace must be written \{. For JSON, use single-quoted text, which is taken exactly as written: json_parse('{"a": 1}').

List methods

MethodReturns
len()The number of items
map(f)A new list with f applied to each item
filter(f)The items for which f is true
try_map(f)A result: f must return results; stops at the first failure
sum()The total of the numbers
join(sep)The items as one piece of text
push(x)Adds an item to the end
pop()Removes and returns the last item
sort(), sorted()Sorts in place; or returns a sorted copy
reverse()Reverses in place
first(), last()An end item, or none if empty
contains(x)Whether the item is present
any(f), all(f)Whether f is true for some / every item
enumerate()A list of [index, item] pairs
slice(a, b)A part of the list
sort_by(f)A new list ordered by the value f gives for each item (equal keys keep their order)
find(f)The first item for which f is true, or none
index_of(x)The position of the item, or -1
unique()A copy without repeated items
flatten()One level of nested lists merged into one
zip(other)A list of [item, other_item] pairs, as long as the shorter list
count(f)How many items f is true for
min(), max()The smallest or largest number, or none if empty
take(n), drop(n)The first n items, or everything after the first n
reduce(f, start)Folds the list into one value: f(total_so_far, item) for each item
group_by(f)A map from each key f gives to the list of items with that key
partition(f)Two lists: the items f is true for, and the rest
chunk(n)The list cut into lists of n
reversed()A reversed copy (reverse() changes the list itself)

Text methods

MethodReturns
len()The number of characters
lines()A list of lines
split(sep)A list of pieces (no argument: split on whitespace)
trim(), upper(), lower()A changed copy
contains(t), starts_with(t), ends_with(t)true or false
replace(a, b)A copy with every a replaced by b
chars()A list of single characters
to_int(), to_float()A result holding the number
pad_left(n, ch), pad_right(n, ch)The text padded to width n (with spaces if ch is left out)
index_of(t)The position of t, or -1
slice(a, b)A part of the text
title()Each word capitalized
count(t)How many times t appears
is_digit(), is_alpha()Whether the text is all digits / all letters
trim_start(), trim_end()Spaces removed from one end
strip_prefix(t), strip_suffix(t)The text without t at the start / end, if it is there

Map methods

MethodReturns
len()The number of entries
keys(), values(), items()Lists (items are [key, value] pairs)
has(k)Whether the key is present
get(k, default)The value, or the default if the key is missing
set(k, v)Adds or changes an entry
remove(k)Removes an entry
merge(other)A new map with both; the other map wins on shared keys
map_values(f)A new map with f applied to every value

Random generator methods

next(), int(low, high), chance(p), pick(list), shuffle(list), fork(). See Simulations.

Result methods

is_ok(), is_err(), unwrap(), unwrap_or(default), error(), map(f), and and_then(f) (if ok, run f on the value; f must itself give back a result, so steps that can fail chain together). See Errors and contracts.

Errors you will meet

Every error shows the file, the line and a suggestion. The common ones: an effect used without needs; a package wanting permissions you didn't grant; wrong types or argument counts; a match that doesn't cover every case; a broken contract; and a run that needs permissions you didn't pass with --allow.