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.Write the code
Open Let’s break this down:
hello.dry and add the following:hello.dry
include: std/io- Imports the standard I/O libraryact: main- Defines the main action (entry point)"Hello, World!\n" prints- Pushes a string to the stack and prints it;- Ends the action definition
Compile the program
Compile using the default GCC backend:This will:
- Compile
hello.dryto C code (build/ir.c) - Compile the standard library
- Assemble the C code to an object file
- Link everything into an executable (
a.out)
You can compile and run in one step using the
-r flag:Understanding the Stack
Dryft is a stack-based language. Values are pushed onto a stack and operations consume them:Example: Simple Arithmetic
Createmath_example.dry:
No operator precedence rules needed! Operations are evaluated left-to-right as they appear.
Variables and Functions
Dryft supports variables and function definitions:Control Flow Example
Let’s create a simple counting program using loops and conditionals:Complete Example: Factorial Calculator
Here’s a more advanced example showing pure functions with variables and loops:Compiler Options
Thedryftc compiler supports several useful options:
Interactive REPL
Dryft includes a REPL (Read-Eval-Print Loop) for interactive development:The x86 backend is not stable in the REPL environment. Use the default GCC backend for REPL sessions.
Example Programs
Explore theexamples/ 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