Tutorial

This tutorial walks through stone from a first program to lists, functions, and input. If you know Python, most of it will look familiar: the differences are mostly a few changes in syntax and a type checker that runs before your program does.

Every program in this tutorial is part of stone’s test suite, which runs it under both the interpreter and the compiler and checks that each prints exactly the output shown.

Your first program

Save this as hello.stn:

print("hello, world")

stone gives you three ways to handle it:

stone run hello.stn          # interpret it
stone build hello.stn && ./build/hello   # compile a native executable
stone check hello.stn        # only look for errors

stone hello.stn is shorthand for stone run hello.stn. Either way, it prints:

hello, world

A single file is enough for small programs. For anything larger, stone init starts a project, a directory with a stone.toml that names it and a main.stn to start from:

stone init hello             # makes hello/stone.toml, hello/main.stn, hello/.gitignore
cd hello
stone run                    # prints Hello, world!
stone build && ./build/hello
stone test                   # runs the test block main.stn starts with

Inside a project, stone run, stone build, and stone check need no file: they use the project’s main.stn, from its directory or any directory inside it. See Command line for the details.

Blocks and indentation

Like Python, stone groups statements by indentation. A line that opens a block ends in :, as in Python, and the indented lines after it are the block:

if 2 > 1:
    print("math still works")

A block with a single statement can also follow the : on the same line, as in if done: break. Comments start with // and run to the end of the line.

Next, Values and types.