Search

beginner

Your First Draft Program

Install Draft, create a project, and write your first program.

Your First Draft Program

Welcome to Draft! In this tutorial, you will install the Draft compiler, create your first project, and run a simple program.

Prerequisites

  • A terminal (macOS, Linux, or Windows)
  • curl or an equivalent download tool

Step 1: Install Draft

Draft is distributed as a single binary. Run the install script for your platform.

macOS / Linux

Terminal window
curl --proto '=https' --tlsv1.2 -sSf https://draft-lang.dev/install | sh

Windows (PowerShell)

Terminal window
irm https://draft-lang.dev/install.ps1 | iex

Step 2: Verify the Installation

Check that the compiler is available:

Terminal window
draft --version

Expected output:

draft 0.1.0

Step 3: Create a New Project

Draft projects contain a main.draft file and an optional configuration file.

Terminal window
mkdir my-first-draft && cd my-first-draft
draft init

Expected output:

Created Draft project in ./my-first-draft
- main.draft
- draft.toml

Step 4: Write Your First Program

Open main.draft and replace the contents with:

action main()
write("Hello, world!")
fin action.

Save the file.

Step 5: Run the Program

Execute the program using the Draft CLI:

Terminal window
draft run main.draft

Expected output:

Hello, world!

How It Works

Draft programs start execution in the main action. The write function prints text to the console. Every action must be closed with fin action.

Key Syntax

Pattern Purpose
action name() Define a function or entry point
fin action Close an action block
write(...) Print output to the console
"string" String literal

Next Steps