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
curl --proto '=https' --tlsv1.2 -sSf https://draft-lang.dev/install | shWindows (PowerShell)
irm https://draft-lang.dev/install.ps1 | iexStep 2: Verify the Installation
Check that the compiler is available:
draft --versionExpected output:
draft 0.1.0Step 3: Create a New Project
Draft projects contain a main.draft file and an optional configuration file.
mkdir my-first-draft && cd my-first-draftdraft initExpected output:
Created Draft project in ./my-first-draft - main.draft - draft.tomlStep 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:
draft run main.draftExpected 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
- Learn about variables and values
- Build a CLI tool
- Explore the standard library
