Welcome

NOTE: Not released yet - finishing up on distribution/documentation

Deft is a TCL-meets-Clojure programming language. It pairs TCL's shell-friendly command syntax with Clojure's data abstractions: immutable persistent data structures, lazy sequences, transducers, protocols, and a rich functional core.

The runtime is written in Zig and compiles to a single self-contained binary with no external dependencies. Scripts are parsed to S-expressions, compiled to bytecode, and executed on a stack-based VM with tail-call optimisation. It's neck and neck with Python on some standard benchmarks.

Does It Work? Can it Scale?

Deft is more than a language, it ships with a full UI platform with functionally equivalent hosts for scripting, GL and Ansi (also embedded). The Deft apps on the right exist with publically available source, the editor has more than 7000 lines of Deft. All apps are interoperable via pubsub or rpc. In fact the Deft platform is very similar to what Emacs offers with a Blender style tiled interface and workspaces. Check out the Highlights page.

Work in Progress, Evaluation

Deft is a WIP, the runtime/language sources are currently not open, however, runtimes binaries and all Deft source for the apps are.

If anyone is interested in commercial opportunites or open sourcing Deft in a Blender style "Free the Source", please contact me ritchie@deft-lang.org.

# Three call forms — pick the one that reads best in context
set name "Alice"
echo "hello $name"                    # bare (top-level statement)
set length $name(len)                 # postfix (single-arg on a variable)
set mid $name(1..3)                   # postfix range slice — chars 1..2
set total ($price * $quantity)        # infix (arithmetic / comparison)

# Pipelines thread a value through a chain

def numbers @{ 1 2 3 4 5 }
def even? {|x^number| [mod $x 2] == 0 }
$numbers |> [filter even?] |> map { $it * 2 } |> collect
# => @{ 4 8 }

# Persistent data: lists, maps, sets, tagged maps
def user %User{ name "Alice" roles ^{:admin :user} }

# Pattern matching
match $user~roles {
    %{ :admin } => "is admin"
    _           => "is not admin"
}

# Protocols and types
deftype Point %{ :x %{} :y %{} }

defimpl Point Drawable {
    draw {|ctx bounds|
        @doc "Draw a point at (x, y)"
        [draw/cell $ctx $self~x $self~y "*"]
    }
}

Language Features

The features that make Deft, Deft.

  • TCL command syntax — [echo "hello"], or top level echo "hello"
  • Infix expressions in parens — ($a + $b), ($n == 0)
  • Postfix sugar on values — $str(trim), $items(first), $m~field
  • Range slicing — "string"(0..1), $list(2..5), $xs(1..) — postfix slices of strings and collections
  • Immutable persistent collections — lists @{}, maps %{}, sets ^{}
  • Lazy sequences & transducers — Clojure-style map/filter/take/comp/into/transduce
  • Pattern matching — match, type patterns, guards, or-patterns, ranges, regex
  • User types & protocols — deftype, defprotocol, defimpl, defmethod
  • Coroutines & async tasks — defcoro + spawn/vwait, deftask + await, defworker + worker/send
  • Macros — Elixir-style defmacro with macro/quote/macro/unquote
  • Native FFI — load shared libraries, call C functions
  • Batteries included — HTTP client/server, SQLite, JSON/YAML, TCP/UDP, regex, crypto

Apps built with Deft

Editors, tools, and games from the packages tree.

Ants Ants
BTC BTC
Charts Charts
Chat Chat
Codegraf Codegraf
Command Command
Config Config
Cube Cube
Desktop Desktop
Diff Diff
Editor Editor
Files Files
Find Find
Flappy Flappy
Git Git
Help Help
Image Image
IRC IRC
Keys Keys
Log Log
Mail Mail
Media Media
Notifications Notifications
Services Services
Sheet Sheet
Shell Shell
Showcase Showcase
SQLite SQLite
Surface Demo Surface Demo
Symbols Symbols
Sysmon Sysmon
Term Term
Tests Tests
Tetris Tetris
Video Video

Benchmarks

Deft vs CPython — representative suite.

✓ closure-like HOF (10k) 0.14ms (avg 0.1ms) 4.2x faster than Python
✓ squares divisible by 3 2.2ms (avg 2.1ms) 1.9x faster than Python
✓ nested reduce (500x500) 5.6ms (avg 5.8ms) 1.7x faster than Python
✓ pipeline (map→filter→reduce) 3.9ms (avg 4.1ms) 1.7x faster than Python
✓ sort 100k comparator 6.8ms (avg 7.0ms) 1.6x faster than Python
✓ ackermann(3,7) 30ms (avg 30.4ms) 1.3x faster than Python
✓ for-loop summation 2.2ms (avg 2.1ms) 1.0x vs Python
✓ map update (10k ops, 1k keys) 0.99ms (avg 1.0ms) 1.0x vs Python
✓ string build+join (10000) 0.75ms (avg 0.8ms) 1.0x vs Python
✓ string interpolation (5000) 1.0ms (avg 1.1ms) 1.1x vs Python
✓ map build (10000 keys) 1.4ms (avg 1.4ms) 1.6x vs Python
✓ csv split/join (25k fields) 4.0ms (avg 4.0ms) 1.6x vs Python
✓ json round-trip (1000 records) 2.0ms (avg 1.9ms) 1.8x vs Python
✓ sort 100k reversed 3.8ms (avg 3.8ms) 2.0x vs Python
✓ fibonacci(25) recursive 12ms (avg 11.9ms) 2.0x vs Python
✓ binary tree (depth=15) 39ms (avg 40.8ms) 2.2x vs Python
✓ word frequency (10k) 1.0ms (avg 1.1ms) 2.9x vs Python

The retro workspace

btc, sysmon, codegraf, sheet and flappy tiled side by side.

retro workspace with btc, sysmon, codegraf, sheet, files, help and flappy panels