Skip to main content

Language Syntax

Dryft is a concatenative, stack-based programming language with a simple and elegant syntax. Programs flow naturally from left to right, with data transformations composed in a readable sequence.

Why Concatenative?

Programming is fundamentally about designing systems with data flowing in complex ways. Dryft’s concatenative style excels at this by making data flow explicit and readable.

Comparison with Traditional Languages

Consider transforming a potato through multiple steps: Traditional nested functions (hard to read):
meal = serve(mash(boil(peel(potato), 10)))
Multiple assignments (verbose):
pure = peel(potato)
cooked = boil(pure, 10)
meal = mash(cooked)
meal = serve(meal)
Dryft concatenative style (elegant):
potato peel 10 boil mash serve

Basic Syntax Elements

Tokens and Whitespace

Dryft code is tokenized by whitespace (spaces, tabs, newlines). Each token represents a value, operation, or keyword:
5 3 +  # Pushes 5, then 3, then adds them

Comments

Comments are delimited by # on both sides:
# This is a comment #
10 20 +  # inline comment # prints

String Literals

Strings are enclosed in double quotes:
"Hello, World!\n" prints

Numeric Literals

Integer literals can be positive or negative:
42      # positive integer
-17     # negative integer

Boolean Literals

Boolean values use true and false:
true
false
4 4 =?  # produces true

Block Delimiters

Dryft uses consistent syntax for defining blocks:
  • Start delimiter: keyword or keyword:
  • End delimiter: :keyword or ;

Examples

fun: factorial
    # function body
:fun

# Alternative with semicolon
fun: square
    copy * ;

# Inline conditionals
true then: "yes" prints ;

No Operator Precedence

Dryft eliminates the need for parentheses and operator precedence rules. Everything is evaluated left-to-right:
# Unambiguous: (6/2)(1+2)
6 2 / 1 2 + *

# Unambiguous: 6/(2(1+2))
6 2 1 + 2 * /

Stack-Based Evaluation

Values are pushed onto a stack, and operations consume values from the stack:
5        # Stack: [5]
3        # Stack: [5, 3]
+        # Stack: [8]

Stack Manipulation

copy  # or ^  - Duplicate top value
drop  # or v  - Remove top value
swap  # Swap top two values

Annotations

Type annotations provide documentation and are enclosed in parentheses:
(Int Int -> Bool)
fun: divby
    mod 0 =? ;
Annotation syntax: (inputs -> outputs)

File Inclusion

Include other Dryft files with the include keyword:
include: std/io
The .dry extension is automatically appended.

Complete Example

include: std/io

# Simple increment function #
fun: inc 1 + ;

# Double a number #
fun: double
    copy + ;

act: main
    "Enter a number: " prints
    5 inc double printi "\n" prints
:act
This example demonstrates Dryft’s clean, readable syntax where data flows naturally through transformations.

Build docs developers (and LLMs) love