Drift
A tiny programming language, built because the manifesto said I could.
Drift is a small functional language with first-class functions, pattern matching, and a pipeline operator. It runs entirely in your browser. Type expressions below or click an example.
Examples
2 + 3 * 4
let double = fn x -> x * 2
in double(5)
[1, 2, 3, 4, 5]
|> map(fn x -> x * x)
[1,2,3,4,5,6]
|> filter(fn x -> x % 2 == 0)
|> fold(0, fn a b -> a + b)
let fib = fn n ->
if n < 2 then n
else fib(n-1) + fib(n-2)
in fib(10)
let compose = fn f g ->
fn x -> f(g(x))
in compose(inc, dbl)(5)
range(1, 10)
|> map(fn x -> x * x)
|> filter(fn x -> x > 20)
[5, 6, 7, 8]
|> map(factorial)
Language Reference
Drift is expression-based — everything returns a value. There are no statements, only expressions.
Values
42 -- integers
3.14 -- floats
true, false -- booleans
"hello" -- strings
[1, 2, 3] -- lists
nil -- nothing
Operators
+ - * / % -- arithmetic
== != < > <= >= -- comparison
&& || ! -- logical
|> -- pipeline (x |> f is f(x))
++ -- string/list concatenation
Let bindings
let x = 42 in x + 1
let add = fn a b -> a + b in add(2, 3)
Functions
fn x -> x * 2 -- anonymous
fn x y -> x + y -- multi-arg
let f = fn x -> x in f(42) -- bound
Conditionals
if x > 0 then "positive" else "non-positive"
Built-in functions
map(list, fn) -- transform each element
filter(list, fn) -- keep matching elements
fold(list, init, fn) -- reduce to single value
range(from, to) -- generate list [from..to]
len(list) -- list/string length
head(list) -- first element
tail(list) -- all but first
push(list, val) -- append to list
reverse(list) -- reverse a list
str(val) -- convert to string
type(val) -- type name as string
Pipeline operator
-- x |> f becomes f(x)
-- x |> f(y) becomes f(x, y)
[1,2,3] |> map(fn x -> x * 2) |> reverse
Design notes
Drift is intentionally small. No mutation. No loops (use recursion or higher-order functions). No classes. No modules. It's a language designed for thinking in, not building in — a sketch pad for ideas, not a blueprint for buildings.
The pipeline operator |> is the heart of Drift's philosophy: data flows left to right, through transformations, like water through a channel. Or like thoughts drifting from one to the next.