Hello World
Let’s create your first Draft program and run it.
Create a New File
Section titled “Create a New File”Create a file named main.draft:
action main() write("Hello, world!")fin action.Understanding the Program
Section titled “Understanding the Program”Let’s break down what this program does:
| Element | Meaning |
|---|---|
action |
Declares the start of a function definition |
main() |
The function name with its parameter list |
write(...) |
Prints output to the console |
fin action. |
Ends the action definition |
Run the Program
Section titled “Run the Program”Navigate to the directory containing main.draft and run:
draft run main.draftYou should see:
Hello, world!Compile to Binary
Section titled “Compile to Binary”To produce a standalone executable:
draft build main.draft -o helloThen run the compiled binary:
./hello # macOS / Linuxhello.exe # WindowsA More Complex Example
Section titled “A More Complex Example”Here’s a program that takes user input:
action main() write("What is your name?") @name = read_line() write("Hello, " + @name + "!")fin action.Run it:
draft run main.draftOutput:
What is your name?> EarlHello, Earl!Key Concepts
Section titled “Key Concepts”- Actions — Functions in Draft are called actions. They start with
actionand end withfin action. - Variables — Prefixed with
@(e.g.,@name). They are immutable by default. - Standard Library —
write()andread_line()are from theiomodule, automatically imported.
Next Steps
Section titled “Next Steps”Learn about Project Structure to organize your Draft projects properly.
