The Control Language is JtV's Turing-complete sublanguage for imperative programming.
| Property | Description |
|---|---|
| Turing-complete | Can compute anything computable |
| Stateful | Modifies variable bindings |
| May not terminate | While loops can run forever |
| I/O capable | Print, input, file operations |
// Empty statement - does nothing
skip
The sole join point between Data and Control:
variable = data_expression
┌─────────────┐ ┌─────────────┐
│ Control │ ←───── │ Data │
│ (variable) │ value │ (expression)│
└─────────────┘ └─────────────┘
statement1
statement2
// Or explicitly:
statement1; statement2
if condition {
// then branch
}
if condition {
// then branch
} else {
// else branch
}
// Nested
if a {
if b {
// ...
}
} else {
// ...
}
while condition {
// body (may execute 0 or more times)
}
Warning: While loops may not terminate!
// This runs forever
while true {
x = x + 1
}
// Range-based (guaranteed to terminate for finite ranges)
for i in 0..10 {
sum = sum + i
}
// Collection-based
for item in collection {
process(item)
}
fn function_name(param1: Type1, param2: Type2): ReturnType {
// body
return value
}
result = function_name(arg1, arg2)
print(expression)
print("Hello, " + name)
State = String → Value
Stmt : ControlStmt → State → State
Control statements transform state.
⟨skip, σ⟩ → σ
⟨x := e, σ⟩ → σ[x ↦ ⟦e⟧(σ)]
⟨S₁, σ⟩ → σ' ⟨S₂, σ'⟩ → σ''
─────────────────────────────────
⟨S₁; S₂, σ⟩ → σ''
⟦b⟧(σ) = true ⟨S₁, σ⟩ → σ'
──────────────────────────────────
⟨if b then S₁ else S₂, σ⟩ → σ'
⟦b⟧(σ) = false ⟨S₂, σ⟩ → σ'
──────────────────────────────────
⟨if b then S₁ else S₂, σ⟩ → σ'
⟦b⟧(σ) = false
─────────────────────────
⟨while b do S, σ⟩ → σ
⟦b⟧(σ) = true ⟨S, σ⟩ → σ' ⟨while b do S, σ'⟩ → σ''
──────────────────────────────────────────────────────────
⟨while b do S, σ⟩ → σ''
⟨S₁, σ⟩ →₁ ⟨S₁', σ'⟩
─────────────────────────────────────
⟨S₁; S₂, σ⟩ →₁ ⟨S₁'; S₂, σ'⟩
⟨S₁, σ⟩ →₁ σ'
─────────────────────────────
⟨S₁; S₂, σ⟩ →₁ ⟨S₂, σ'⟩
────────────────────────
⟨skip, σ⟩ ⇓ σ
⟨S₁, σ⟩ ⇓ σ' ⟨S₂, σ'⟩ ⇓ σ''
─────────────────────────────────
⟨S₁; S₂, σ⟩ ⇓ σ''
Control Language functions have purity levels:
| Level | Loops | I/O | Callable from Data |
|---|---|---|---|
| @total | ✗ | ✗ | ✓ |
| @pure | ✓ (bounded) | ✗ | ✓ |
| (none) | ✓ | ✓ | ✗ |
// Total - no loops, no I/O, guaranteed termination
@total fn increment(x: Int): Int {
return x + 1
}
// Pure - may loop but no I/O
@pure fn multiply(a: Int, b: Int): Int {
result = 0
for i in 0..b {
result = result + a
}
return result
}
// Impure - can do anything
fn greet(name: String): Unit {
print("Hello, " + name)
}
Control Language supports reversible execution:
reverse {
x += 5 // Forward: x = x + 5
y += x // Forward: y = y + x
}
// Automatically generates:
// y -= x // Backward: y = y - x
// x -= 5 // Backward: x = x - 5
fn factorial(n: Int): Int {
result = 1
for i in 1..n+1 {
// Multiply via repeated addition
temp = 0
for j in 0..i {
temp = temp + result
}
result = temp
}
return result
}
fn fibonacci(n: Int): Int {
if n <= 1 {
return n
}
a = 0
b = 1
for i in 2..n+1 {
temp = a + b
a = b
b = temp
}
return b
}
fn processUserInput(input: String): Int {
// User input is DATA, not CODE
value = parseInt(input) // Returns Int, not executable code
// Even malicious input like "'; DROP TABLE users; --"
// is just a string that fails parseInt
if value >= 0 {
return value + 100
} else {
return 0
}
}
Control Language enforces unidirectional flow:
Data Language ──────→ Control Language
values
Control Language ──✗──→ Data Language
cannot create
new expressions