Skip to main content

Quick Start

This guide will walk you through creating and running your first Dryft program.

Your First Program: Hello World

Let’s start with the classic “Hello, World!” example.
1

Create a new file

Create a file named hello.dry:
touch hello.dry
2

Write the code

Open hello.dry and add the following:
hello.dry
include: std/io

act: main
    "Hello, World!\n" prints ;
Let’s break this down:
  • include: std/io - Imports the standard I/O library
  • act: main - Defines the main action (entry point)
  • "Hello, World!\n" prints - Pushes a string to the stack and prints it
  • ; - Ends the action definition
3

Compile the program

Compile using the default GCC backend:
dryftc hello.dry
This will:
  1. Compile hello.dry to C code (build/ir.c)
  2. Compile the standard library
  3. Assemble the C code to an object file
  4. Link everything into an executable (a.out)
4

Run the executable

Execute your program:
./a.out
Output:
Hello, World!
You can compile and run in one step using the -r flag:
dryftc hello.dry -r

Understanding the Stack

Dryft is a stack-based language. Values are pushed onto a stack and operations consume them:
# Push 3 and 4 onto the stack, then add them
3 4 +        # Stack: [7]

# Push another value and multiply
2 *          # Stack: [14]

Example: Simple Arithmetic

Create math_example.dry:
include: std/io

act: main
    # Solve: (6/2)(1+2)
    "(6/2)(1+2) = " prints
    6 2 / 1 2 + * printi
    "\n" prints
    
    # Solve: 6/(2(1+2))
    "6/(2(1+2)) = " prints
    6 2 1 + 2 * / printi
    "\n" prints
;
Compile and run:
dryftc math_example.dry -r
Output:
(6/2)(1+2) = 9
6/(2(1+2)) = 1
No operator precedence rules needed! Operations are evaluated left-to-right as they appear.

Variables and Functions

Dryft supports variables and function definitions:
include: std/io

# Pure function: doubles a number
fun: double
    copy + ;

# Pure function: increments a number
fun: inc
    1 + ;

act: main
    # Store value in variable
    5 var: x
    
    # Use the variable
    $x double printi "\n" prints
    
    # Update the variable
    $x inc x!
    $x printi "\n" prints
;
5 var: x          # Declare and initialize x with 5
$x                # Read variable x (pushes value to stack)
10 x!             # Update x with new value (10)

Control Flow Example

Let’s create a simple counting program using loops and conditionals:
include: std/io

act: main
    10 var: max
    0 var: i
    
    cycle:
        $i $max =? then break ;
        $i printi " " prints
        $i 1 + i!
    :cycle
    
    "\n" prints
;
Compile and run:
dryftc count.dry -r
Output:
0 1 2 3 4 5 6 7 8 9

Complete Example: Factorial Calculator

Here’s a more advanced example showing pure functions with variables and loops:
include: std/io

# Calculate n!
fun: factorial var: n
    1 var: result
    cycle: $n 0 =? then break ;
        $result $n * result!
        $n 1 - n!
    :cycle
    $result
:fun

act: main
    "10! = " prints
    10 factorial printi
    "\n" prints
;
Output:
10! = 3628800

Compiler Options

The dryftc compiler supports several useful options:
# Compile with default target (GCC)
dryftc program.dry

# Compile and run
dryftc program.dry -r

Interactive REPL

Dryft includes a REPL (Read-Eval-Print Loop) for interactive development:
dryftc
Example REPL session:
Dryft repl> 3 4 + printi
7
Dryft repl> 5 var: x
Dryft repl> $x 10 * printi
50
Dryft repl> .help
.help/help  => display this screen
.exit/.quit => leave the REPL, terminating this process
.view       => inspect the contents of generated IR from last execution
Dryft repl> .exit
The x86 backend is not stable in the REPL environment. Use the default GCC backend for REPL sessions.

Example Programs

Explore the examples/ directory for more complex programs:

hello.dry

Simple “Hello, World!” program

fizzbuzz.dry

Classic FizzBuzz with conditionals and loops

math.dry

Mathematical functions: factorial and exponentiation

example.dry

Comprehensive feature showcase

Next Steps

Now that you can write and compile Dryft programs, dive deeper into the language:

Language Guide

Learn Dryft’s syntax, types, and features in detail

Standard Library

Explore available standard library functions

Examples

Study complete example programs

Type System

Understand Dryft’s linear type system

Common Patterns

Printing Values

42 printi              # Print integer
"Hello" prints         # Print string
"\n" prints            # Print newline

Stack Manipulation

copy                   # Duplicate top of stack
swap                   # Swap top two values

Comparisons

5 5 =?                 # Equal? Returns bool
5 3 >?                 # Greater than?
5 3 <?                 # Less than?
5 5 >=?                # Greater than or equal?

Conditionals

# Simple conditional
true then: "yes" prints ;

# If-else with when
when:
    condition then: "yes" ;
    "no" ;
prints
You’re now ready to start building with Dryft!

Build docs developers (and LLMs) love