Getting started

Cresset needs only Node.js (version 18 or newer). There is nothing else to install.

Run your first program

Create a file called hello.crs:

fn main() needs print:
    name = "world"
    print("Hello, {name}!")

Run it:

node cresset.js run hello.crs

On Windows you can use the wrapper scripts in the project folder instead: cresset run hello.crs, or the short form cr run hello.crs.

A program always starts at fn main(). The needs print part is a permission: it says main is allowed to print.

Permissions at run time

By default a program may only print. Anything else must be granted when you run it:

node cresset.js run examples/scores.crs --allow read

Without --allow read, Cresset refuses to start the program and tells you what it asked for. Use --allow-all only for programs you wrote and trust.

Check without running

node cresset.js check examples/denied.crs

check reads the program, verifies permissions and types, and runs nothing. It also lists each function and what it needs.

Try things interactively

node cresset.js repl
>>> 1 + 2
3
>>> name = "Ada"
>>> name.upper()
"ADA"
>>> fn double(x):
...     return x * 2
...
>>> double(21)
42
>>> read("notes.txt")
error: this line uses 'read', which needs the 'read' permission, but doesn't declare it
help: start the REPL with that permission:  cresset repl --allow read

The REPL keeps your variables and definitions between lines, and you can define a function or record again to replace it. A line ending in : starts a block; finish it with a blank line. .vars lists your variables, .defs your definitions, .exit leaves.

It follows the same rules as a file: a session can only use what you grant it with --allow, and every line is checked before it runs. (input can't be granted, because the REPL is already reading what you type.)

Test your code

Put test "name": blocks next to your code and run cresset test file.crs. See Testing.

Format your code

node cresset.js fmt hello.crs --write

fmt puts code in one standard style: 4-space indentation, spaces around operators, one blank line between top-level definitions. It keeps your comments and never changes what a program means (the project's tests check that on every example). Without --write it prints the result; with --check it only says whether the file would change.

Editor support

The folder editors/vscode in the project is a VS Code extension with syntax highlighting, errors underlined as you type (the same messages and suggestions as the command line), code completion, hover (signature, permissions and your doc comment), go to definition (including inside imported packages), an outline view, format-on-request, automatic indentation after a line ending in :, and snippets (main, fn, record, enum, match, use and more). Its README explains how to install it, and what has and hasn't been tested.

Other editors and CI can use node cresset.js check file.crs --json, which prints every problem as data.

The shape of a program

Try it in the browser

The playground runs the whole language in your browser. Pick an example, change it, and press Run. The permission checkboxes control what the program may do, so you can see for yourself what happens when a permission is missing.

Next

Read the language tour.