edva
an implementation of dva
A zero-bare-keyword, expression-oriented systems language.
Language by Example
Explore syntax, symbolic control flow, algebraic types, and performance.
Symbolic Control Flow
Edva has zero bare keywords — words like if, for, and return are ordinary identifiers, while meta-level directives live in the #-prefixed namespace (#use, #type, #foreign).
|introduces choices and fallback branches[guard]supports value, range ([90..100]), predicate, or variant guards@iterates over ranges, arrays, or streams-->and--^provide symbolic break and continue
#use io
// Conditionals & multi-guard pattern matching
classify: Int => String
classify = score =>
score
[100] "perfect"
[90..100] "distinction"
[50..90] "pass"
| "fail"
// Iteration with @ and symbolic cycle control
10 @ i =>
i [7] --> // --> breaks the cycle
io::out $ classify(i * 10)
Algebraic Ramifications
Rams represent binary outcomes (presence/absence, success/failure) with compact unboxed storage.
- Four shapes:
<>,<T|>,<|E>,<T|E> - Monadic bind
$>>and positive map$+> - Postfix error propagation via
--! - Inline default fallback via
|_|
#use fs
#use json
// Monadic bind ($>>) chains optional lookups
find_user: String => < User | >
find_user = id =>
query_db(id) $>> validate $>> (<+ _ +>)
// Postfix error propagation (--!) unwraps or early-returns
load_config: String => < Config | Error >
load_config = path =>
raw = fs::read_to_string(path)--!
cfg = json::parse(raw)--!
<+ cfg ->
In-Place Builders & Strings
Strings are immutable fat pointers. Builders provide high-throughput in-place buffering with zero-copy freeze.
b = {N}allocates an initial buffer with capacityNb += "...${expr}..."streams templates directly with zero intermediate allocationb += (13, 10)appends raw CRLF byte tuples directly+bfreezes the buffer into an immutable String with zero copy
// Pure strings & in-place builders
build_report: String[] => String
build_report = items =>
b = {128} // initial capacity hint
b += "# Report Summary\n\n"
items @ item =>
b += " - ${item}\n" // zero-alloc streaming
b += (13, 10) // CRLF byte tuple
+b // O(1) freeze to String
Native Networking
Fast HTTP request routing and response formatting built purely on Edva's standard library with zero GC overhead.
- Triple-quoted
"""..."""strings allow unescaped JSON quotes - Choice guards dispatch routes cleanly without boilerplate
- Scoped arenas reset per request with zero heap fragmentation
- Direct LLVM compilation and native link
#use str
route: String => (Int, String, String)
route = path =>
path
["/"]
(200, "text/plain", "Hello, Edva!")
["/health"]
(200, "application/json", """{"status":"ok"}""")
|
(404, "text/plain", "Not Found: ${path}")
Expression Cycles (@>)
Transform, filter-map, fold, and freeze collections into strings with zero intermediate iterator objects.
xs @> (_ * 2)maps into a fresh collection- Returning
<+ val +>performs fused filter-map in one pass (seed, xs) @> (+)folds left with any binary operator or closure+(xs @> ...)streams chunks straight into a frozenString
#use io
nums = Int{}(1, 2, 3, 4, 5, 6)
// Map, filter-map, and seeded fold via @>
doubled = nums @> (_ * 2)
evens = nums @> (n => (n .&. 1) == 0 | <+ n * 10 +>)
sum = (0, evens) @> (+)
// Direct freeze into a String with unary +
csv = +(nums @> (n, i => i > 0 | ",${n}" | "${n}"))
io::out $ "${csv} (sum=${sum})"
Expressive Power & Low-Level Precision
Modern ergonomics paired with mechanical sympathy
Pipelines & Sections
Chain functions with multi-argument feed and point-free operator sections.
$>feeds the LHS as the first argument to RHS$applies multi-argument functions with infix precedence(2 * _)desugars to a clean inline lambda- Zero wrapper closures generated at runtime
#use io
// Multi-argument feed ($>) and operator sections
bound: Int, Int, Int => Int
bound = val, lo, hi => %clamp(val, lo, hi)
raw = 150
// Feeds raw into bound, then applies section (2 * _)
result = raw $> bound(0, 100) $> (2 * _)
io::out $ result
Cycle Escapes & Jumps
Cycles evaluate as expressions returning binary ramifications.
i [target]value guard checks equality (equivalent toi == target)-->breaks innermost cycle;-->Njumps N outer levels--^continues innermost iteration>--turns cycles into expressions yielding< T | >- Produces
<+ val +>on break,<-->on completion
#use io
// Cycle-escape (>--) returns < Int | >
find_target: Int, Int => < Int | >
find_target = count, target =>
count @ i =>
i [target] --> // matches i == target; breaks
>--
target
res = find_target(10, 7)
res | io::out(_) | io::out $ "Not found"
SIMD & Vector Math
Hardware-accelerated element-wise operations with zero glue code.
- Homogeneous records map directly to LLVM vector registers
- Element-wise arithmetic:
+,-,*,/ - Scalar broadcasting across vector operands
0 {N}postfix repetition creates flat records
#use io
// LLVM SIMD operations on homogeneous records
pos = (10, 20, 30, 40)
vel = (1, 2, 3, 4)
// Element-wise addition and scalar broadcast multiply
next_pos = pos + vel * 2
io::out $ next_pos.0 // 12
io::out $ next_pos.3 // 48
Explicit Mutability
Deterministic immutability by default, with clear visual mutation boundaries.
- Bindings are immutable by default;
=is used uniformly - Rebindable variables require trailing primes:
x',x'' - Function parameters are permanently immutable
- Interior record mutations (
pt.x = ...) require no primes
#use io
#type Point (x: Int, y: Int)
// Unprimed bindings allow interior field mutation
pt = Point(10, 20)
pt.x = 42
// Rebindable local variables declare with a prime (')
total' = 0
5 @ i =>
total' = total' + i
io::out $ total' + pt.x // 52
Records & Copy-Update
Nominal C-ABI structs with default field values, destructuring, and concise functional updates.
#zero Tinitializes a nominal record with its declared defaultsr $> _(field = val)performs copy-with-update in pipelines without repeating the type- Positional destructuring
(a, b, _) = recunpacks fields cleanly - Distinct
#typerecords never accidentally unify
#use io
#type Config (host: String = "127.0.0.1", port: Int = 8080, tls: <> = <->)
// Defaults via #zero and pipeline copy-with-update
base = #zero Config
prod = base $> _(host = "0.0.0.0", port = 443, tls = <+>)
// Record destructuring
(host, port, _) = prod
io::out $ "${host}:${port}"
Systems Programming & Direct Hardware Access
Zero-cost abstractions with bare-metal control
File I/O & Memory
Direct POSIX file descriptor handling with zero-copy buffer transfers.
libc::openopens native POSIX file descriptorsb = {4096}allocates an in-place Builder buffermem::write_tailreserves tail space and bounds-checks the written count+bfreezes into aStringwithout copying
#use libc
#use mem
// Zero-copy file read using Builder buffer
read_file: String => < String | >
read_file = path =>
fd = libc::open(path, 0)
fd < 0 |-->
b = {4096}
n = mem::write_tail(b, 4096, (dst, avail => libc::read(fd, dst, avail)))
libc::close(fd)
n > 0 | <+ +b +>
LLVM Intrinsics
Compiler-level intrinsics lowered directly to target processor instructions.
%-prefixed intrinsics lower to LLVM IR without calls%dotand%sumfor hardware SIMD reductions%clampand%usub_satfor saturating math- Zero runtime overhead or library dependency
// Hardware-accelerated LLVM intrinsics
a = (1, 2, 3)
b = (4, 5, 6)
// Vector reductions & dot products
dot_prod = %dot(a, b) // llvm.fmuladd / SIMD
total = %sum(a) // llvm.vector.reduce.add
// Bounding & saturating arithmetic
clamped = %clamp(120, 0, 100) // 100
sat_sub = %usub_sat(5, 10) // 0 (unsigned sat)
Tagged Enums
Type-safe algebraic data types with compact unboxed payloads.
#type Name <Variants>defines closed algebraic types- Variant guards
[Tag payload]and[Tag (a, b)]bind fields directly - Deep structural equality with
==compares tag and payload - Unboxed register storage for single-scalar variants
#use io
#type Shape < Circle(Float), Rect(Float, Float) >
// Variant pattern matching binds & destructures payloads
area: Shape => Float
area = s =>
s
[Circle r] 3.14 * r * r
[Rect (w, h)] w * h
c = Shape(Circle, 10.0)
io::out $ area(c) // 314.0
Bitwise Operators
Predictable low-level binary manipulation with UB-safe bit shifts.
.<.and.>.zero-fill shifts masked to operand width.&.bitwise AND and.|.bitwise OR.!.unary bitwise negation (integers and runes only)- Explicit type suffixes:
0xFFu8,0b1010u16,1i64
// Bitwise operators & UB-safe bit shifts
mask = 0x01 .|. 0x04 // bitwise OR: 5
// Test bitmask flags (.&. binds looser than !=)
has_flag = (mask .&. 0x04) != 0
// Logical shift left with masked operand width
offset = 1 .<. 8 // 256
Packed Types & Bitfields
Exact binary wire layouts and sub-byte bitfields with compile-time size verification.
#type(packed)emits 1-byte aligned structs with zero padding#type(packed = u16)packs bit-width fields into an exact carrier integer#size Tand#align Tquery exact ABI layout at compile time- Field reads/writes lower directly to shift-and-mask LLVM instructions
#use io
// 1-byte aligned wire header (zero struct padding)
#type(packed) PacketHdr (version: u8, flags: u8, length: u16, seq: u32)
// Packed 16-bit bitfield backed by u16
#type(packed = u16) CtrlWord (ver: 4, kind: 4, len: 8)
hdr = PacketHdr(1u8, 0x04u8, 128u16, 42u32)
cw = CtrlWord(2u8, 5u8, 64u8)
io::out $ "hdr=${#size PacketHdr}B, cw=${#size CtrlWord}B, seq=${hdr.seq}, kind=${cw.kind}"
Collections, Interop & Architecture
Growable collections, C ABI interop, hermetic packaging, and compile-time evaluation
Growable Arrays
Dynamically sized collections with unboxed layouts, zero hidden overhead, and bounds-checked safety.
T{}orT{N}initializes dynamic arrays with optional capacity hintsarr += itemappends elements in-place with amortized resizing?arrqueries element length;++arrperforms an explicit deep copyarr @> (_ * 2)maps cleanly;arr(i) |_| 0handles bounds safely
// Initialize growable array with capacity hint (64)
scores: Int{64}
// In-place append using +=
scores += 95
scores += 88
scores += 100
// Query count (?), deep clone (++), and expression map (@>)
total = ?scores
backup = ++scores
doubled = scores @> (_ * 2)
// Safe bounds-checked lookup with |_| default
first = scores(0) |_| 0 // 95
safe = scores(5) |_| 0 // 0 (out of bounds)
Foreign Function Interface
Zero-overhead native interoperability calling C functions directly with LLVM ABI linkage.
#foreign("c")declares typed foreign signatures without header wrappers- Nullary functions are invoked with postfix
!(getpid!) - First-class non-null
Addr& 0-niche< Addr | >map directly to C pointers - Zero runtime bridge overhead, marshaling layers, or garbage collection stalls
// Declare foreign C ABI functions directly
#foreign("c")
puts: (s: String) => Int
getpid: () => Int
isatty: (fd: Int) => Int
// Invoke native POSIX symbols seamlessly
pid = getpid!
is_term = isatty(1) != 0
is_term | puts("Interactive terminal detected")
| puts("Standard output redirected to pipe")
Packages & Modules
Hermetic package resolution, clean encapsulation, and zero global namespace pollution.
#use @pkgimports versioned dependencies from the package import map#use(import) strbrings module symbols into current scope unqualified#publicblocks define export APIs; unlisted symbols stay module-privatesrc/internal/submodules enforce strict package-private boundary visibility
// Package dependency and unqualified stdlib import
#use @crypto/sha256
#use(import) str
#public
sign_payload: String => String
sign_payload = data =>
salt = "edva-secret-salt"
"${data}${salt}" $> sha256::digest $> to_hex
// Unexported functions remain private to this module
validate: String => < | String >
validate = token =>
?token > 32 | <++> | <- "Token too short" ->
Compile-Time & Here-Docs
First-class compile-time evaluation, Unicode runes, repetition, and multiline here-documents.
#constevaluates expressions at compile time and folds static constants"""..."""here-docs with baseline margin stripping and${expr}interpolation- Unescaped
"and""work as-is; direct in-place lowering into Builders expr {N}repetition constructs flat, register-allocated records
// Compile-time constant folding with #const
buf_size = #const (4096 * 4)
port_mask = #const ((1 .<. 16) - 1)
// Triple-quoted here-doc with margin stripping & interpolation
user = "Alice"
count = 3
report = """
Hello, ${user}!
Items remaining: ${count}
Note: unescaped "quotes" and ""double quotes"" work as-is.
"""
// Repetition literal (0 {8}) and 32-bit Unicode Rune
zero_block = 0 {8}
badge = '⚡
Generics & Reflection (#)
Zero-RTTI monomorphized generics paired with compile-time type introspection.
#param T: Typespecializes functions per concrete call type#members T @ f, i =>unrolls record fields or enum variants at compile time#name T,#size T, and#has_member T, fresolve statically- Zero runtime type descriptors or dynamic dispatch overhead
#use io
#type Point (x: Int, y: Int)
// Monomorphized generic + compile-time reflection (#)
describe: #param T: Type, T => String
describe = #param T, val =>
fields = {64}
#members T @ f, i =>
i > 0 | fields += ", "
fields += f.name
"${#name T} (${#size T}B): { ${+fields} }"
io::out $ describe(Point(3, 4))