Getting Started
Go from zero to your first Deft script in under five minutes.
1
Install Deft
Deft ships as a single binary. Download and put it on your PATH:
# Build from source (requires Zig 0.15+)
git clone https://github.com/deft-lang/deft-zig
cd deft-zig && zig build
# Verify installation
./zig-out/bin/deft_zig --version
2
Your first script
Use deft eval for quick one-liners, or create a .dft file:
# Quick evaluation
deft eval 'echo "Hello, Deft!"'
# => Hello, Deft!
# Math with grouping
deft eval '(2 + 3) * 4'
# => 20
3
Variables & Collections
Assign with set, reference with $. Deft has lists, maps, and sets built in:
# Variables set name "Alice" echo "Hi, $name!" # Lists set items @{ 1 2 3 4 5 } [map $items {| x | ($x * 2)}] # => @{ 2 4 6 8 10 } # Maps set config %{ host "localhost" port 8080 } echo $config~host # => localhost
4
Functions
Define functions with def. Parameters use type hints with ^:
def greet {| name^string | echo "Hello, $name!" } [greet "World"] # => Hello, World! # Multi-clause (dispatch on arity/type) def area {| r^number | (3.14159 * $r * $r)} def area {| w^number h^number | ($w * $h)}
5
Interactive REPL
Launch the interactive shell and experiment:
deft shell
# Now you're in the REPL -- try anything:
deft> set x @{ 10 20 30 }
deft> [reduce $x 0 {| a b | ($a + $b) }]
60
6
Build an HTTP server
Create app.dft and serve it:
def index {| req res | [html <h1>My Deft App</h1> <p>Hello from the Deft HTTP server! </p> \html] } def app %{ routes @{ %{ path "/" method :GET handler index } } } |> [http/router]
deft serve http app.dft --port 3000
# Starting HTTP server on http://localhost:3000